it won't print my str please help it has worked before but just now it won't work
name ' ' is not defined error
name ' ' is not defined error
|
it won't print my str please help it has worked before but just now it won't work
Mar-23-2019, 01:01 PM
Copy and paste your code using python tags, and put the full text of the error message in output tags.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness. Recommended Tutorials: BBCode, functions, classes, text adventures import math while True: try: tal = int(input("tal?: ")) except ValueError: print("kun tal") n = tal for p in range(2,n): moudu = n%p prime = "det er et primtal" if moudu == 0: prime = "det er ikke et primtal" break ianden = tal*tal print (prime) print ("² = ", ianden) print ("kvadratrod =", math.sqrt(tal)) input('Press enter to continue: ')
Mar-23-2019, 01:09 PM
The variable prime only gets defined if a value greater than 2 is entered. If you enter 1 on the first try, the loop on line 9 never executes, and prime never gets defined. Note that if you enter 1 on the second try, it uses the value of prime from the previous try. You need to set a value to prime before that loop.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness. Recommended Tutorials: BBCode, functions, classes, text adventures
Mar-23-2019, 01:16 PM
thank you very much.
this really helped my day :) |
|
Users browsing this thread: 2 Guest(s)