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

17th Apr 2020, 7:18 AM
M.O.HONOR
M.O.HONOR - avatar
1 Respuesta
+ 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
17th Apr 2020, 7:36 AM
Ipang