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 trialAdam Cameron
Python Web Development Techdegree Graduate 16,731 Points"unsupported operand type(s)" - What's wrong with my solution?
I'm getting the following error on my solution here:
"unsupported operand type(s) for *: 'FakeQuiz' and 'float'"
Can anyone tell me what's wrong with my code? Thanks in advance!
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(questions):
return '{}/{}'.format(math.ceil(questions * .7), total_questions)
from django.contrib import admin
from . import models
class QuizAdmin(admin.ModelAdmin):
list_display = ['title', 'course']
2 Answers
Adam Cameron
Python Web Development Techdegree Graduate 16,731 PointsI was being careless. Figured it out but then forgot to wrap everything in a function. Here's what finally worked:
class Quiz(Step):
total_questions = models.IntegerField()
def number_correct_needed(self):
return '{}/{}'.format(math.ceil(self.total_questions * .7), self.total_questions)
Samuel Ferree
31,722 PointsWhat is the data type for the questions variable in Quiz.number_correct_needed()?
That's the only place in your code I'm seeing the * operator used on a variable, and a float.
Adam Cameron
Python Web Development Techdegree Graduate 16,731 PointsOkay I'm embarrassed - I had things pretty backwards. I don't even need that extra questions
variable. Trying this line now but it's still not working, just saying "Bummer, try again!"
return '{}/{}'.format(math.ceil(total_questions * .7), total_questions)
Adam Cameron
Python Web Development Techdegree Graduate 16,731 PointsSorry, figured it out. Forgot to put everything in a function. Relaxed a little too much over the holidays I guess. Thank you for your help!