name ' ' is not defined error - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: name ' ' is not defined error (/thread-16986.html) |
name ' ' is not defined error - nonzzo - Mar-23-2019 it won't print my str please help it has worked before but just now it won't work RE: name ' ' is not defined error - ichabod801 - Mar-23-2019 Copy and paste your code using python tags, and put the full text of the error message in output tags. RE: name ' ' is not defined error - nonzzo - Mar-23-2019 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: ')
RE: name ' ' is not defined error - ichabod801 - Mar-23-2019 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. RE: name ' ' is not defined error - nonzzo - Mar-23-2019 thank you very much. this really helped my day :) |