本文介绍了如何在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?
推荐答案
这篇关于如何在python中将字符串输入转换为int?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!