如何在python中将字符串输入转换为int?
问题描述:
def tie():
guess = random.randint(1,100)
opp = random.randint(0,100)
number = input(guess);
diff1 = (guess - opp)**2
diff2 = (guess - number)**2
if diff2 > diff1:
print("You won the tie breaker!")
elif diff2 < diff1:
print("You lose the tie breaker")
blackjack();
这是我的代码。我希望能够找出哪个人更接近随机数。 Opp(对手)或数字(我自己)。但我得到一个错误,说字符串不能用作int。帮助任何人?
This is my code. I want to be able to find out which person is closer to the random number. Opp (opponent) or number(myself). But I get an error saying string cant be used as int. Help anyone?