0
how to end the infinite While loops on str for python3?
for example (I'm just messing around with this): words = ["spam", "egg", "spam", "sausage"] guess = input("Tell me what's inside this: ") print(guess) if(guess in words) == True: print('right') while True: if("spam" in words): x= "You have won the lottery" i want it to loop 4 times
1 ответ
+ 3
I would recommend to use for-loop instead of a while-loop, knowing you have already decided how many times the loop should run.
for i in range(4):
if "spam" in words:
# do what you want here