找到成本,但它一直返回错误
my_money = input('How much money do you have? ')
boat_cost = 20 + 5
if my_money < boat_cost:
print('You can afford the boat hire')
else :
print('You cannot afford the board hire')
my_money = input('How much money do you have? ')
boat_cost = 20 + 5
if my_money < boat_cost:
print('You can afford the boat hire')
else :
print('You cannot afford the board hire')
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试此代码段,查看原始代码问题:
Try this code snippet and see the original code problem:
输入
通常是字符串。为了使其工作,您需要使用y = int(x)
将其转换为整合器。(尽管不是一个编程)中,
中也存在错误,它说如果他们的钱低于成本,他们可以负担得起租金。
正确的代码,没有解决第二个错误,就会像这样:
input
is normally a string. In order for this to work you need to convert it to an integrer by usingy = int(x)
.There is also an error in the
if
, albeit not a programming one, where it says that they can afford the hire if their money is less than the cost.The correct code, without fixing the second error, would look like this:
input()
函数允许在控制台中输入用户。但是该输入是一个字符串,您不能将其用作数学操作。
因此,
int()
是一个符合字符串并返回整数的函数。您必须使用
int(input())
要获得只能是数字的输入时。因此,替换:
如果说明逻辑是错误的,则应该是:
仅
当您的价格相同或更高时,您就可以负担得起船
The
input()
function allows user input in the console.But that input is a string, you cannot use it as a mathametical operation.
So
int()
is a function that takes a string and returns the integer.you have to use
int(input())
when you want to get an input that can only be a number.so replace:
and your if statement logic is wrong it should be :
instead of
you can afford the boat only when your price is same or higher