我正在尝试在Python上构建一个程序。这是程序的一部分,问题就在这里。当我在Python中运行它时,它通过'task_name=input(“What is the task”)行运行,但是当我把它放到Python visualizer时,它给了我一个错误:NameError:name'input'没有定义。下面这段程序只是我程序的开始,在它运行完这段程序之后,我需要它来运行我程序的其余部分,但是它会停止并重复这个部分。如果我没有很好地解释这一点,我很抱歉,如果你不明白,尽管问。请回答,我需要在明天之前完成这个程序!
我使用了pythonvisualizerhttp://www.pythontutor.com/visualize.html#mode=display,我使用的是python3.2.1.1newTask = "y"
while newTask == "y":
try:
numStudents = int(input("How many students are there?"))
except ValueError:
print("An integer please")
continue
else:
if numStudents <=1:
print("You must enter more than 1 student.")
task_name = input("What is the task?")
while numStudents == 0:
for i in range (1,numStudents):
cont = "y"
while cont == "y":
import random
vol_num = random.randint (1,numStudents)
print(vol_num) #remove, needs to be hidden
break
print("The task is", task_name, ".", "If your number matches the secret number you must complete this task. Good luck!!")
print("There are", numStudents-student_num, "numbers left which means you have 1 chance in", numStudents, "of being the volunteer!")
student_name = input("What is your name? Please enter your first name in letters with a maximum of 15.")
while student_name.isalpha() != True or len(task_name) > 15:
print("Your first name must be entered in letters with a maximum of 15 letters.")
student_name = input("What is your name?")
student_num == 0
while student_num == 0:
try:
student_num = int(input("What is your number? Please enter it as an integer."))
except ValueError:
print("You number must be entered as an integer.")
continue
else:
if student_num < 1 or student_num > numStudents:
print("That is not a valid number. Please enter the number you were given.")
student_num = int(input("What is your number?"))
if student_num == vol_num:
print("You are the volunteer! Please complete the task of", task_name, ".")
else:
print("You were lucky this time! You do not have to complete the task!")
cont = input("Are you the next student? y/n")
while cont == "n":
newTask = input("Would you like to enter a new task? (y/n")