repeat a value in python code example
Example 1: how to repeat if statement in python
def main():
while True:
again = raw_input("Would you like to play again? Enter y/n: ")
if again == "n":
print ("Thanks for Playing!")
return
elif again == "y":
print ("Lets play again..")
else:
print ("You should enter either \"y\" or \"n\".")
if __name__ == "__main__":
main()
Example 2: how to repeat code in python until a condition is met
a = 1
b = 1
while (a<10):
print ('Iteration',a)
a = a + 1
b = b + 1
if (b == 4):
break
print ('While loop terminated')