import sys
def displayGreeting():
print("\nThe Wizard will see you now."
+ "\n"
+ "\nOK, let's get started\n")
def askQuestions():
counter = 0
name = input("What's your name? ")
age = checkAge()
numOfQuestions = checkNumofQuestions()
for counter in range(1, numOfQuestions + 1):
question = input("\nWhat's your question?")
if question.strip() == "":
print("You should enter a question")
continue
if question.strip().lower() == 'bye':
break
else:
message = processQuestion(counter, question)
print(message)
print("\nNo more questions for you!")
print("Stop bothering the Wizard!")
def checkNumofQuestions():
numOfQuestions = input("\n\nHow many Questions do you want to ask the wizard? ")
if numOfQuestions.isnumeric():
numOfQuestions = int(str(numOfQuestions))
numOfQuestions += 1
print("I am giving you a bonus. You can ask", numOfQuestions, "questions!")
else:
print("Warning: ", numofQuestions, "is not a Valid number! I am changing it to 5")
numOfQuestions = 5
return numOfQuestions
def checkAge():
while True:
age = input("What is your age? ")
if age.isnumeric():
age = int(age)
if age < 10 or age > 80:
print("please enter a valid age between 10 and 80")
elif age > 30 and age < 50:
print("these are prime earning years")
break
else:
print("you are a good age to play this game")
break
else:
print("Please enter a valid integer for your age")
return age
def processQuestion(counter, question):
if question.startswith("Who"):
message = "Who, Who... isn't that a sound an owl makes?"
elif question.startswith("What"):
message = "What is the meaning of life?"
elif question.startswith('How'):
message = "How now, brown cow?"
else:
message = "I don't know"
message = str(counter) + ". The Wizard answers: " + message + "?"
return message
def main():
print("Assignment 4\n")
print("* * The Wizard Game * *")
playGame = input("Do you want to talk to the Wizard? (Yes or No) ")
playGame = playGame.strip()
if playGame.lower() == "yes":
displayGreeting()
askQuestions()
else:
print("The Wizard wants you to go away now!")
print("\n\nEND OF PROGRAM")
main()
我甚至不知道从哪里开始。我尝试了一些方法,但毫无帮助。我仍然有错误。
以下是完整的回溯错误:
Traceback (most recent call last):
File "filename.py", line 107, in <module>
main()
File "filename.py", line 101, in main
askQuestions()
File "filename.py", line 19, in askQuestions
for counter in range(1, numOfQuestions + 1):
TypeError: unsupported operand type(s) for +: 'NoneType' and 'int'