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 trialLynn Collins
10,080 PointsOk, so this is my first Python code ever. It does okay but the def ask_again function keeps returning an error.
It returns an error and won't even prompt a "yes/no" response from the user. How can I resolve this? Any input would be most helpful...thanks!
def factorial(n):
if n <= 0:
return 0
elif n == 1:
return 1
else:
fact = 1
while(n > 1):
fact *= n
n -= 1
return fact
def getNumberFromUser():
num = int(input("Please input whole a number under 11: "))
if (num <= 10):
return num
else:
print ("Sorry wrong number!")
return -1
def ask_again():
cont = ''
while cont not in ("yes", "no"):
cont = input("Another one?(yes/no) ").lower()
if cont == "yes":
return cont
else:
break
#print("You chose",num)
while True:
result = -1
while (result < 0):
result = getNumberFromUser()
fact = factorial(result)
print("Factorial of ", result, "is", fact)
[MOD: added ```python formatting -cf]
1 Answer
Chris Freeman
Treehouse Moderator 68,441 PointsI can not cause the error you are seeing. The code runs as-is. There does not seem to be a call to execute ask_again
Chaquayla Halmon
1,797 PointsChaquayla Halmon
1,797 PointsHey I'm also new to Python too. This is a great course. For this problem is there a way we can see the entire code. If you're working in a work space there's a button at the left of the workspace that takes a snapshot of your code. You can copy and paste it on here. That way we can look at the syntax as well as the error. Thank you.