Python Forum

Full Version: Loops
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
#Game
#Import module
import random

#Start randomgenerator
random.seed()

#Random values and calculation
a= random.randint(1,10)
b= random.randint(1,10)
c= a+b
print("The exercise:",a,"+",b)
#Loop with [for]
for i in 1,2,3,4:
      #Input
      print("Input number:") 
      x=input()
      number= int(x)

#Branch
if number == c:
      print(number,"is correct")
      #Break of Loop
      break 

else:
      print(number, "is wrong")

#End
print("Answer:",c)
when i try to run it, it says the 'break' is out of the loop. when imove it it says elif is a Syntax error. Need help
Quote:when i try to run it, it says the 'break' is out of the loop. when imove it it says elif is a Syntax error. Need help
You don't have an elif. Please post exact unaltered and complete error message (in error tags)

Your if/else is not part of loop, to make it so, indent 2 levels