Я новичок в python и стараюсь сделать простую бумагу, рок, ножницы. независимо от того, что я делаю внутри своей «хромой» функции, значение локальной переменной «y» не будет присвоено глобальной переменной «var1» или «var2». Я пытался использовать возврат, но не могу заставить работать.Функция python wont возвращает значение
#get input (paper, rock scissors from players)
play1 = input("player 1:")
play2 = input("player 2:")
#set value of players score to 0
val1 = 0
val2 = 0
def lame(x, y):
#set value of p, r, s choice, to 1, 2 or 3
if x in("p","P"):
y = y + 1
elif x in("r","R"):
y = y + 2
elif x in("s","S"):
y = y + 3
else:
print("your value was not p, r or s")
#run function "lame" and pass in "play1" choice and
#retrieve "val1" for that choice
lame(play1, val1)
lame(play2, val2)
def win(x, y):
#subtracts value of players choices to find winner
dif = x - y
if dif == 0:
print("tie game")
elif dif % 3 == 1:
print("player 2 wins")
elif dif % 3 == 2:
print("player 1 wins")
else:
print("logic error")
#call function "win" and pass in results of their choices
win(val1, val2)
Python не делает вызов по ссылке с номерами. Вам нужно будет фактически установить значения «val1» и «val2» для этих значений, а не 'y' – L3viathan