I am learning Python (using 3.6.2) and in their last class, they asked me to do something where I need to do an infinite loop . For some reason, the teacher does not want us to use for the whole practice. Here it gets complicated ... for
while
So, I was looking for a way to do this. But it’s also difficult because the teacher doesn’t want us to use commands that we did not see in the classroom . Therefore, I can not use the functions .append, sys, well, I can not even use the break. I have to find a way to do with the "simple" commands .
I thought I could do it like this;
x=1
for i in range(x):
do_something()
x += 1
However, this did not seem to work. I think that since Python no longer reads the value for the range?
I could not find a way, but after several hours of reflection, I found a small solution that I could use:
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):
return exit()
else:
print("ERROR: Please insert a valid number")
return ex():
def exit():
pass
As you can see, what makes it “infinite” is that it returns to the function once and again until you tell the program to “exit” by entering “666”. I would also like to have a more correct way to exit the function.
I am still wondering if there is a better way to make my loop endless until the user calls it to stop. However, one way or another I got this exercise. The problem arose when I started with the second one , which more or less looks like this:
, , . , , . (), "" .
, , , . , .
. , , while:( , - , ...
, 3 :
, , .
, , - :)
EDIT: , itertools
, , , . , for
?