小编Kir*_*Sim的帖子

Python打印出浮点数或整数

如果结果有小数,我如何打印出浮点数或如果结果没有小数则打印出整数?

c = input("Enter the total cost of purchase: ")
bank = raw_input("Enter the bank of your credit card (DBS, OCBC, etc.): ")
dbs1 = ((c/float(100))*10)
dbs2 = c-dbs1
ocbc1 = ((c/float(100))*15)
ocbc2 = c-ocbc1


if (c > 200):
    if (bank == 'DBS'):
        print('Please pay $'+str(dbs2))
    elif (bank == 'OCBC'):
        print('Please pay $'+str(ocbc2))
    else:
        print('Please pay $'+str(c))
else:
    print('Please pay $'+str(c))

exit = raw_input("Enter to exit")
Run Code Online (Sandbox Code Playgroud)

例如,结果

Enter the total cost of purchase: 250
Enter the bank of your credit …
Run Code Online (Sandbox Code Playgroud)

python if-statement coding-style string-formatting

3
推荐指数
3
解决办法
9167
查看次数