這是我當前的代碼,當我運行它時,出現一些錯誤......我不確定它們是什麼。我的錯誤在哪裏? (54行代碼)
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()
謝謝,這使它工作。 – Ryan