Reputation: 21
bank = 0
cash = 0
userinput = input('would you like to work? ')
if userinput == 'y':
print('working...')
newcash = 100
newcash + cash
print(cash)
When ever I run the program, it would return the cash value to 0.
Upvotes: 1
Views: 69
Reputation: 33
It is because you have to assign it like that:
cash = newcash + cash
instead of
newcash + cash
Upvotes: 1
Reputation: 75
In your code, the variable cash is not updating when you doing addition (newcash + cash
), returning 0 is correct answer for your current code.I think you want something like that :
bank = 0
cash = 0
userinput = input('would you like to work? ')
if userinput == 'y':
print('working...')
newcash = 100
cash += newcash
print(cash)
Now you will get your answer.
Upvotes: 1
Reputation: 1284
Instead of using newcash + cash
, you want to add the value of the variable newcash
to the variable cash
like so
cash = cash + newcash
or if you prefer a little "cleaner"
cash += newcash
Upvotes: 3
Reputation: 2921
newcash + cash
is a result never assigned to anything. Try calling cash += newcash
instead, or cash = newcash + cash
.
Upvotes: 4