Python Forum

Full Version: pyython code copied 1to1 from book not working.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello im a Programming Beginner and learning form a book. Everything worked so far extemley well and im making Progress but this Python Script doesnt seem to work. I get syntax error on ELIF and i dont know why.



#initzialize random number generator
import random
random.seed()


#init variables

a = random.randint(1,100)
b = random.randint(1,100)
c = a + b

#Question
print ("Die Aufgabe lautet:", a, b)

#userinput
print ("Bitte Zahl eingeben:")
zahl = input()
zahl = float(zahl)

#results
if zahl == c:
    print("Super Das Ergebnis ist richtig")
elif zahl < 0 or zahl > 100:
    print("Ganz Falsch")
elif zahl c-1  <= zahl <= c+1: #in this line im getting syntax error. ELIF is red underlined. and i dont know why
    print("Du bist ganz nahe dran")
else:
    print("Falsch")
Thank You For your Help :)
line 25
elif zahl(EXTRA zahl or SOMETHING_MISSING_HERE) c-1 <= zahl <= c+1:
You probably wanted line 25-26 to be

elif c-1  <= zahl <= c+1:
    print("Du bist ganz nahe dran")