我正在学习Python(使用3.6.2),在我上一堂课上,他们让我做一些我需要进行无限for循环的事情.出于某种原因,老师不希望我们while用于整个练习.这是它变得复杂的地方......
所以,我一直在寻找一种方法来做到这一点.但是,这也很困难,因为老师不希望我们使用我们在课堂上没有看到的任何命令.所以我不能使用.append,sys函数,好吧,我甚至不能使用休息.我必须找到一种方法来处理"简单"命令.
我以为我可以这样做;
x=1
for i in range(x):
do_something()
x += 1
Run Code Online (Sandbox Code Playgroud)
但是,它似乎没有用.我认为那是因为Python没有再次读取该范围的值?
我找不到办法,但经过几个小时的思考后,我发现自己可以使用一个小的解决方法:
def ex():
print("Welcome")
for i in range(1):
math = int(input("Please insert grades obtained at Math, or insert 666 to exit" ))
if(math > 0 and math < 60):
print("Sorry. You failed the test")
return ex():
elif(math >= 60 and math <= 100):
print("Congratulations. You passed the test")
return ex():
elif(math == 666): …Run Code Online (Sandbox Code Playgroud)