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 trialHeidi Ulrich
4,624 PointsHow can I output total_questions right?
This is the error I get: Bummer! unsupported operand type(s) for *: 'float' and 'FakeQuiz'
I tried this in my own console, by passing in '10' or '20' as integer into the total_questions var. Works like a charm. But here, it doesn't.
Somehow, I get 'FakeQuiz' passed in, and of course that's not an integer you can calculate with.
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()
def number_correct_needed(total_questions):
percentage = 0.7
needed = int(percentage * 10)
return "%d/%d" % (needed, total_questions)
from django.contrib import admin
from . import models
class QuizAdmin(admin.ModelAdmin):
list_display = ['title', 'course']
2 Answers
Kenneth Love
Treehouse Guest TeacherThat's an instance method so what should the very first argument to it be/represent?
bryonlarrance
16,414 PointsHeidi
Here is my process:
def number_correct_needed(self):
num_ques = self.total_questions #pulled from the Quiz model
average = ((num_ques/100)*70)
return "{}/{}".format(math.ceil(average), math.ceil(num_ques))
I thought that I wouldn't need the math.ceil on my num_questions since that would be an int coming from the model, but this challenge requires it. Hope that helps.