mercredi 22 avril 2015

Where are my errors? (54 lines of code)

This is my current code and when I run it, I get a few errors...and I'm not sure what they 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' is not defined

def main():
    print("Welcome to Ryan's book club!")
    booksread = int(input('Please enter the amount of books you have read so far: '))
#   if (booksread < 0):
#       print("That's impossible! Please  re-enter the amount of books you have read: ")
#       booksread1 = int(input('Please enter the amount of books you have read so 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()

Aucun commentaire:

Enregistrer un commentaire