I have made (or more, I'm trying to make) a program to help me calculate some figures. I have some levels that each give a reward and to give out the rewards I prefer to not insert each amount and add them all up to get the totals.
I've made it so that I write the level number, it adds the amount to a list, it loops again, I insert a different number etc.
But it doesn't loop or add the numbers to the list.
Heres my super un-compact code:
lists = []
total = 0
def moneyz():
level=input('-> ')
print('g') #just a testing bookmark
print(level) #same here
if level==1:
print('oo') #and here
lists.apped('150')
total==total+150
elif level == 2:
lists.apped('225')
total==total+225
moneyz()
elif level == 3:
lists.apped('330')
total==total+330
moneyz()
elif level == 4:
lists.apped('500')
total==total+500
moneyz()
elif level == 5:
lists.apped('1000')
total==total+1000
moneyz()
elif level == 6:
lists.apped('1500')
total==total+1500
moneyz()
elif level == 7:
lists.apped('2250')
total==total+2250
moneyz()
elif level == 8:
lists.apped('3400')
total==total+3400
moneyz()
elif level == 9:
lists.apped('5000')
total==total+5000
moneyz()
elif level == 10:
lists.apped('15000')
total==total+15000
moneyz()
moneyz()
print(lists)
print(total)
I can see three bugs in this code:
levelis astr, so it will never equal anint. None of yourifchecks will ever be satisfied, which is why your function isn't recursing. A way to spot this in debugging would have been to add aprint(repr(level))after you receive the input; you'd see that it's a value like'1'(a string) instead of1(an integer).apped(), so once you hit that line of code (which currently isn't happening because yourifchecks never match), it'd raise anAttributeError.totalis never going to increase because you're using the==(equality check) operator rather than the=(assignment) operator.Here's a much shorter (working) version of the program, using a simple lookup table in place of a bunch of
ifstatements: