python - 老虎机程序中每次循环都会中断

标签 python python-3.x

我试图通过说来打破循环

if deff <= int(total):
    break

但是无论输入是负数还是大于总数,循环都会中断

我做错了什么有什么建议吗?

P.S 我知道我会新一个公式来决定玩家是赢还是输。现在我只是想在去那里之前弄清楚第一个代码

第一次编程,老师没有帮助):

<小时/>
def intro():

    greeting()

    print('How much money do you want to start with?')

    print('Enter the starting amount of dollars.', end='')
    total = int(input())

    print('Your current total is '+ str(total)+'\n')
    while True:

        print('How much money do you want to bet (enter 0 to quit)?', end='');
    # Bett will be the amount of money that the player will play with

        bett = int(input())
        if bett > int(total):
            print('ERROR You don\'t have that much left')

        if bett < int(0):
            print('ERROR: Invalid bet amount\n')

        if bett <= int(total)
            break

# Function shows results of slot machine after handle being pulled
def random():
    import random

    num1 = random.randint(1, 5)
    num2 = random.randint(1, 5)
    num3 = random.randint(1, 5)

    print('/---+---+---\  ')
    print('|-'+ str (num1)+'-|-'+ str(num2) +'-|-'+ str (num3) +'-|')
    print('\---+---+---/  ')



intro()
<小时/>

最佳答案

在后续的条件测试中需要使用elifelse:

    bett = int(input())
    if bett > total:
        print('ERROR You don\'t have that much left')

    elif bett < 0:
        print('ERROR: Invalid bet amount\n')

    else:
        break

这样,只执行其中一条语句,而不是执行更多或更多语句。

注意: 对于已经是 int

的东西,没有必要一直使用 int() 构造函数

关于python - 老虎机程序中每次循环都会中断,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15014156/

相关文章:

python - 做一个测验,用 python 从 csv 文件询问随机问题

python - 如何在数据集中使用 read_csv 并以损坏的管道 "¦"作为分隔符???

python - 从图像计算峰度

python - 如何创建一个 python 字典来存储多个帐户的用户名和密码

html - python color entire pandas dataframe rows 基于列值

python - wxPython 程序只显示灰屏

python - 如何在 matplotlib 动画上添加图例?

python - 无法启动 gunicorn.service : Unit gunicorn. 找不到服务。 Ubuntu 18.04

Python 3.3.2 - 'Grouping' 字符系统

python-3.x - 如何使用 asyncio 在 Python 3 中异步运行 requests.get?