如何解决我不知道错误在我的代码中
我是python的新手,无法找到我的错误在哪里。 Python表示存在语法错误,但不会告诉我它在哪里。我的任务是制定一个可以计算出租车费的程序。这是我的代码。
distance = input("Enter the distance of the taxi ride in kilometers (km): ")
passengers = input("Enter the amount of passengers from 1 to 5: ")
cost = float(distance) + 3 - 1 * 2
if passengers == 5:
cost = cost * 2
print("The total cost of the journey is £" cost)
else:
print("The total cost of the journey is £" cost)
错误可能很简单,但我找不到它。预先感谢。
解决方法
如果您想使用print()
功能打印一些内容,则需要用逗号分隔
尝试一下:
print("The total cost of the journey is £",cost)
,
如果您使用的是python 3.6或更高版本,请不要串联字符串:
distance = input("Enter the distance of the taxi ride in kilometers (km): ")
passengers = input("Enter the amount of passengers from 1 to 5: ")
cost = float(distance) + 3 - 1 * 2
if passengers == 5:
cost = cost * 2
print(f"The total cost of the journey is £ {cost}")
else:
print(f"The total cost of the journey is £ {cost}")
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。