I just started learning to code.
I'm trying to write this simple counter. It works on the first run, however when the loop calls "while()" it resets both "r" and the lists "we_list" "you_list". I can't figure how to store their value even after the loop.
def begin():
r = 1
print("This is a counter for the game Belote")
print("Round " + str(r))
we_list = []
you_list = []
we = int(input("Enter score for 'We' "))
we_list.append(we)
we_sum = sum(we_list)
you = int(input("Enter score for 'you' "))
you_list.append(you)
you_sum = sum(you_list)
print("WE " + str(we_sum))
print("YOU " + str(you_sum))
r += 1
while we_sum or you_sum < 151:
begin()
else:
print("End of game ")
exit()
begin()
Edit:
I edited the code with the suggestions, and managed to fix r and and the lists, however now the problem that I have is that it does not break out of the loop after 151.
we_list = []
you_list = []
def begin(r):
print("This is a counter for the game Belote")
print("Round " + str(r))
we = int(input("Enter score for 'We' "))
we_list.append(we)
we_sum = sum(we_list)
you = int(input("Enter score for 'you' "))
you_list.append(you)
you_sum = sum(you_list)
print("WE " + str(we_sum))
print("YOU " + str(you_sum))
r += 1
while we_sum or you_sum < 151:
begin(r)
else:
print("End of game ")
exit()
r=1
begin(r)