python - Where are my errors? (54 lines of code) -
this current code , when run it, few errors...and i'm not sure are.
traceback (most recent call last):
file "d:/.actual w4/lab3problem1.py", line 54, in main()
file "d:/.actual w4/lab3problem1.py", line 8, in main nestediffunction()
file "d:/.actual w4/lab3problem1.py", line 27, in nestediffunction if (booksread == 0):
nameerror: name 'booksread' not defined
def main(): print("welcome ryan's book club!") booksread = int(input('please enter amount of books have read far: ')) # if (booksread < 0): # print("that's impossible! please re-enter amount of books have read: ") # booksread1 = int(input('please enter amount of books have read far: ')) #simpleiffunction() nestediffunction() #eliffunction() def simpleiffunction(): if (booksread == 0): print('you have 0 points!') if (booksread == 1): print('you have 5 points!') if (booksread == 2): print('you have 15 points!') if (booksread == 3): print('you have 30 points!') if (booksread >= 4): print('you have 60 points!') def nestediffunction(): if (booksread == 0): print('you have 0 points!') else: if (booksread == 1): print('you have 5 points!') else: if (booksread == 2): print('you have 15 points!') else: if (booksread == 3): print('you have 30 points!') else: if (booksread >= 4): print('you have 60 points!') def eliffunction(): if (booksread == 0): print('you have 0 points!') elif (booksread == 1): print('you have 5 points!') elif (booksread == 2): print('you have 15 points!') elif (booksread == 3): print('you have 30 points!') elif (booksread >= 4): print('you have 60 points!') main()
you have pass in booksread variable in main area. allows function know number books user entered. function uses numbooksread variable stored passed variable can used in function.
nestediffunction(booksread) def nestediffunction(numbooksread): if (numbooksread == 0): print('you have 0 points!') else: if (numbooksread == 1): print('you have 5 points!') else: if (numbooksread == 2): print('you have 15 points!') else: if (booksread == 3): print('you have 30 points!') else: if (numbooksread >= 4): print('you have 60 points!')
Comments
Post a Comment