Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Loops
#1
#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
Reply
#2
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
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020