python如何表示空字符_如何在python中实现空字符串

我需要能够提示用户输入一个空字符串,以便它可以检查答案是否正确。但每次这样做,我都会错误地说int()的无效文本

所以我需要更改我的user_输入,以便它可以接受int()和strings()。我怎样才能做到呢?在# program greeting

print("The purpose of this exercise is to enter a number of coin values")

print("that add up to a displayed target value.\n")

print("Enter coins values as 1-penny, 5-nickel, 10-dime,and 25-quarter.")

print("Hit return after the last entered coin value.")

print("--------------------")

#print("Enter coins that add up to 81 cents, one per line.")

import sgenrand

#prompt the user to start entering coin values that add up to 81

while True:

total = 0

final_coin= sgenrand.randint(1,99)

print ("Enter coins that add up to", final_coin, "cents, on per line")

user_input = int(input("Enter first coin: "))

if user_input != 1 and user_input!=5 and user_input!=10 and user_input!=25:

print("invalid input")

else:

total = total + user_input

while total <= final_coin:

user_input = int(input("Enter next coin:"))

if user_input != 1 and user_input!=5 and user_input!=10 and user_input!=25:

print("invalid input")

else:

total = total + user_input

if total > final_coin :

print("Sorry - total amount exceeds", (final_coin))

elif total < final_coin:

print("Sorry - you only entered",(total))

else:

print("correct")

goagain= input("Try again (y/n)?:")

if goagain == "y":

continue

elif goagain == "n":

print("Thanks for playing ... goodbye!" )

break

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值