未检测到我变量中的数字

时间:2018-10-02 16:00:47

标签: python-3.7

好吧,所以我正在做一种迷你游戏,它会生成一个随机数,无论它生成的数字是多少,都会决定哪匹马赢得了比赛。您可以在开始时下注,如果您的选择正确,那么您将获胜。但是我的问题是,当我正确下注时,总是说“您的赌注输了!”我一直在搜索,找不到问题。

print ("Welcome to the Horse Race!")
print ("The horses racing are, Horse 1, Horse 2, Horse 3 and Horse 4.")
print ("who are you betting on? (Type the horse number)")
bet = input()
int(bet)
print ("The Horses are racing! who will win?")
import time
time.sleep(1)
from random import randrange

winner = randrange(1, 4)
int(winner)
if winner == 1:
     print("Horse 1 has won!")
     if bet == 1:
      print("Your bet won!")

elif winner == 2:
     print("Horse 2 has won!")
     if bet == 2:
          print("Your bet won!")

elif winner == 3:
    print("Horse 3 has won!")
    if bet == 3:
         print("Your bet won!")

elif winner == 4:
    print("Horse 4 has won!")
    if bet == 4:
         print("You bet won!")

if bet != winner:
     print("Your bet lost! Sorry!")

1 个答案:

答案 0 :(得分:1)

您要将bet从字符串强制转换为整数,但没有保存强制转换的值。

int(bet)更改为bet = int(bet),它应该可以工作。

请注意,这也适用于int(winner),尽管由于randrange()已经返回了整数,所以不需要强制转换。