I've tried many times to do this but after each time it is run the variable i made is still set to 0 but after the last time it is run it is set to 1, a way to do this? here's my code so far.
how do i make it so whenever it loops through the next time the value of amount won't be 0
EDIT 1: new code:
global amount, penny, pebble, rock, bottle, cap, ten_dollar_note, percentage
pebble = 0
rock = 0
bottle = 0
cap = 0
penny = 0
ten_dollar_note = 0
amount = 0
percentage = random.randint(0, 100)
if percentage <= 10:
ten_dollar_note += 1
amount += 1
elif percentage <= 35:
rock += 1
amount += 1
elif percentage <= 45:
pebble += 1
amount += 1
elif percentage <= 65:
cap += 1
amount += 1
elif percentage <= 85:
penny += 1
amount += 1
random_percentage = random.randint(15,31)
times = 0
while times != random_percentage:
overworld_choose()
times += 1
amount_one = amount```
the problem now is that each loop i want to add the value of the function before to it so i tried to do amount_one = amount + 0 but it doesnt seem to work
I fixed it all i had to do is add a variable outside of the functoin called new_amount and make this the while loop:
while times != random_percentage:
overworld_choose()
times += 1
amount1 = amount
new_amount += amount```
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.