Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialTobias Mahnert
89,414 PointsStuck with this Code Challenge
Stuck... Who can help me out or give me a useful tipp?
Add a method to the Quiz model, named number_correct_needed that returns a string showing the number of correct answers needed to get at least 70% on the quiz. Your string should include the number needed and the total number. An example would be "7/10". Use the ceil function in the math module which has already been imported for you.
from django.db import models
import math
class Step(models.Model):
title = models.CharField(max_length=255)
description = models.TextField()
order = models.IntegerField(default=0)
class Meta:
abstract = True
ordering = ['order',]
def __str__(self):
return self.title
class Quiz(Step):
total_questions = models.IntegerField()
from django.contrib import admin
from . import models
class QuizAdmin(admin.ModelAdmin):
list_display = ['title', 'course']
2 Answers
Tobias Mahnert
89,414 PointsNever Mind I just solved it and I'd like to share my solutionas others may stuck and get frustrated as well. This is for task one
def number_correct_needed(self):
total = self.total_questions
needed = ((total/100)*70)
return "{}/{}".format(math.ceil(needed), math.ceil(total))
รyvind Andreassen
16,839 PointsThis is also a valid solution. No need to ask for ceil on the total number of questions, since we can presume that a quiz don't have 4.5/6.7/14.2/ect. questions.
def number_correct_needed(self):
return "{}/{}".format(math.ceil(self.total_questions*0.7), self.total_questions)
Erika Suzuki
20,299 PointsErika Suzuki
20,299 PointsSo, this means, I would have to study math in order for me to complete this challenge by myself.