Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/363.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 当现金与产品的差额为负值时,我如何处理现金产出不足的问题_Python - Fatal编程技术网

Python 当现金与产品的差额为负值时,我如何处理现金产出不足的问题

Python 当现金与产品的差额为负值时,我如何处理现金产出不足的问题,python,Python,当现金与产品的差额为负值时,我如何处理现金产出不足的问题 cash = float(input('How much money did you recieve? ')) acer1 = (299.99) acer2 = (399.99) acer3 = (499.99) insufficient_balance = 'Insufficient Cash' negative_numbers = -1 while negative_numbers < -999_999: print(n

当现金与产品的差额为负值时,我如何处理现金产出不足的问题

cash = float(input('How much money did you recieve? '))
acer1 = (299.99)
acer2 = (399.99)
acer3 = (499.99)
insufficient_balance = 'Insufficient Cash'
negative_numbers = -1
while negative_numbers < -999_999:
    print(negative_numbers)
    negative_numbers += -1
model = input('What model do you want? ')
if model == 'acer1':
    print('Change: ')
    print(cash - acer1)
    print('Thank you for shopping with us')
elif model == 'acer2':
    print('Change: ')
    print(cash - acer2)
    print('Thank you for shopping with us')
elif model == 'acer3':
    print('Change: ')
    print(cash - acer3)
    print('Thank you for shopping with us')
cash=float(输入('你收到多少钱?'))
acer1=(299.99)
acer2=(399.99)
acer3=(499.99)
余额不足=“现金不足”
负数=-1
当负数<-999\u 999时:
打印(负数)
负数+=-1
model=input('您想要什么型号?')
如果型号='acer1':
打印('更改:')
打印(现金-acer1)
打印('谢谢您与我们一起购物')
elif模型==“acer2”:
打印('更改:')
打印(现金-acer2)
打印('谢谢您与我们一起购物')
elif模型==“acer3”:
打印('更改:')
打印(现金-acer3)
打印('谢谢您与我们一起购物')

计算更改后,使用if/else打印错误消息(如果更改为负数)或成功消息

if model == 'acer1':
    change = cash - acer1
    if change < 0:
        print('Insufficient Cash')
    else:
        print(f'Change: {change}')
        print('Thank you for shopping with us')
如果模型=='acer1':
零钱=现金-1
如果变化小于0:
打印(“现金不足”)
其他:
打印(f'Change:{Change}')
打印('谢谢您与我们一起购物')
你可以使用字典来简化一些事情:

inventory = {
     'acer1' : 299.99,
     'acer2' : 399.99,
     'acer3' : 499.99
}
cash = float(input('How much money did you receive? '))
model = input('What model do you want? ').lower()
if model in inventory:
    change = cash - inventory[model]
    if change < 0:
        print('Insufficient Cash')
    else:
        print(f'Change: {change}')
        print('Thank you for shopping with us')
inventory={
“acer1”:299.99,
“acer2”:399.99,
‘acer3’:499.99
}
现金=浮动(输入('你收到多少钱?'))
model=input('您想要什么型号?')。lower()
如果模型在库存中:
变更=现金-存货[型号]
如果变化小于0:
打印(“现金不足”)
其他:
打印(f'Change:{Change}')
打印('谢谢您与我们一起购物')

最后,由于四舍五入错误,对货币使用浮点通常不是一个好主意。

计算更改后,如果更改为负数,则使用if/else打印错误消息或成功消息

if model == 'acer1':
    change = cash - acer1
    if change < 0:
        print('Insufficient Cash')
    else:
        print(f'Change: {change}')
        print('Thank you for shopping with us')
如果模型=='acer1':
零钱=现金-1
如果变化小于0:
打印(“现金不足”)
其他:
打印(f'Change:{Change}')
打印('谢谢您与我们一起购物')
你可以使用字典来简化一些事情:

inventory = {
     'acer1' : 299.99,
     'acer2' : 399.99,
     'acer3' : 499.99
}
cash = float(input('How much money did you receive? '))
model = input('What model do you want? ').lower()
if model in inventory:
    change = cash - inventory[model]
    if change < 0:
        print('Insufficient Cash')
    else:
        print(f'Change: {change}')
        print('Thank you for shopping with us')
inventory={
“acer1”:299.99,
“acer2”:399.99,
‘acer3’:499.99
}
现金=浮动(输入('你收到多少钱?'))
model=input('您想要什么型号?')。lower()
如果模型在库存中:
变更=现金-存货[型号]
如果变化小于0:
打印(“现金不足”)
其他:
打印(f'Change:{Change}')
打印('谢谢您与我们一起购物')

最后,由于舍入错误,使用浮点表示货币通常不是一个好主意。

我想如果我在编码学校教书,我会让每个人在干黑板上写100次”。也许还要加上为什么你要用2.7和3.x来标记这个?我想如果我在编码学校教书,我会让每个人在干黑板上写100遍。也许还要加上为什么要用2.7和3.x来标记这个?