Python Forum
pyython code copied 1to1 from book not working.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
pyython code copied 1to1 from book not working.
#1
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 :)
Reply
#2
line 25
elif zahl(EXTRA zahl or SOMETHING_MISSING_HERE) c-1 <= zahl <= c+1:
99 percent of computer problems exists between chair and keyboard.
Reply
#3
You probably wanted line 25-26 to be

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


Possibly Related Threads…
Thread Author Replies Views Last Post
  New to Python - Not sure why this code isn't working - Any help appreciated TheGreatNinx 4 961 Jul-22-2023, 10:21 PM
Last Post: Pedroski55
  code not working when executed from flask app ThomasDC 1 892 Jul-18-2023, 07:16 AM
Last Post: ThomasDC
  I am new to python and Could someone please explain how this below code is working? kartheekdas 2 1,017 Dec-19-2022, 05:24 PM
Last Post: kartheekdas
Exclamation My code is not working as I expected and I don't know why! Marinho 4 1,081 Oct-13-2022, 08:09 PM
Last Post: deanhystad
  My Code isn't working... End3r 4 1,931 Mar-21-2022, 10:12 AM
Last Post: End3r
  Why changing data in a copied list changes the original list? plumberpy 3 2,236 Aug-14-2021, 02:26 AM
Last Post: plumberpy
  I don't undestand why my code isn't working. RuyCab 2 1,990 Jun-17-2021, 03:06 PM
Last Post: RuyCab
  code is not working , can anybody help? RandomPerson69 4 2,910 Mar-22-2021, 04:24 PM
Last Post: deanhystad
  Short code for EventGhost not working Patricia 8 3,688 Feb-09-2021, 07:49 PM
Last Post: Patricia
  Code no longer working yk303 14 10,180 Dec-21-2020, 10:58 PM
Last Post: bowlofred

Forum Jump:

User Panel Messages

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