好的,所以我对编程世界很陌生并编写了一些非常基本的程序,因此为什么我的代码有点混乱。所以我得到的问题是老师需要帮助她的学生完成任务。她随机给学生们他们的数字。然后学生将他们的号码输入到程序中,然后程序会告诉他们是否已经吸引了短杆。该课程必须能够根据课堂上学生的数量来运行,这就是我被困的地方,我无法根据班上学生的数量找到运行课程的方法。这是我的代码
import random
print("Welcome to the Short Straw Game")
print("This first part is for teachers only")
print("")
numstudents = int(input("How many students are in your class: "))
task = input("What is the task: ")
num1 = random.randint(0, numstudents)
count = numstudents
print("The part is for students") #Trying to get this part to run again depending on number of students in the class
studentname = input("What is your name:")
studentnumber = int(input("What is the number your teacher gave to you: "))
if studentnumber == num1:
print("Sorry", studentname, "but you drew the short straw and you have to", task,)
else:
print("Congratulations", studentname, "You didn't draw the short straw")
count -= 1
print("There is {0} starws left to go, good luck next student".format(count))
答案 0 :(得分:1)
简单地说,将剩下的代码整理成一个:
# ...
print("The part is for students")
for i in range(numstudents):
studentname = input("What is your name:")
#...
另外,欢迎来到编程世界! :)祝你好运,玩得开心!