为什么我的提示计算器刚刚返回$ 0.00?
我正在学习学习python的课程,这是他们给我们的任务
“”“在美国,在餐厅用餐后为您的服务器留下小费,通常等于您的餐点15%或更多。不用担心,我们已经为您写了一个小费,
def main():
dollars = dollars_to_float(input("How much was the meal? "))
percent = percent_to_float(input("What percentage would you like to tip? "))
tip = dollars * percent
print(f"Leave ${tip:.2f}")
def dollars_to_float(d):
# TODO
def percent_to_float(p):
# TODO
main()
已经为您写了大部分提示计算器。
我们 应接受str作为输入(格式为$ ##。##,其中每个#都是十进制数字),删除领先的$,并将其返回为float,例如$ 50.00。 。 percon_to_float应该接受str作为输入(格式为##%,其中每个#都是十进制数字),删除尾随%,然后将百分比返回为浮点。例如,给定15%作为输入,应返回0.15。 假设用户将以预期格式输入值。”““
您最终应该得到的是 这顿饭是多少? $ 50.00 您想提示什么百分比? 15% 留下$ 7.50 我的问题是无论我输入什么数字,我最终每次都会获得“ $ 0.00”。这就是我写的,
def main():
dollars = dollars_to_float(input("How much was the meal? "))
percent = percent_to_float(input("What percentage would you like to tip? "))
tip = dollars * percent
print(f"Leave ${tip:.2f}")
def dollars_to_float(d):
str.lstrip(d)
return float(d)
def percent_to_float(p):
str.rstrip(p)
return float(p)
main()
请帮助!
Im taking a course for learning python and this is the assignment they gave us
"""In the United States, it’s customary to leave a tip for your server after dining in a restaurant, typically an amount equal to 15% or more of your meal’s cost. Not to worry, though, we’ve written a tip calculator for you, below!
def main():
dollars = dollars_to_float(input("How much was the meal? "))
percent = percent_to_float(input("What percentage would you like to tip? "))
tip = dollars * percent
print(f"Leave ${tip:.2f}")
def dollars_to_float(d):
# TODO
def percent_to_float(p):
# TODO
main()
Well, we’ve written most of a tip calculator for you. Unfortunately, we didn’t have time to implement two functions:
dollars_to_float, which should accept a str as input (formatted as $##.##, wherein each # is a decimal digit), remove the leading $, and return the amount as a float. For instance, given $50.00 as input, it should return 50.0.
percent_to_float, which should accept a str as input (formatted as ##%, wherein each # is a decimal digit), remove the trailing %, and return the percentage as a float. For instance, given 15% as input, it should return 0.15.
Assume that the user will input values in the expected formats."""
What you should end up getting is
How much was the meal? $50.00
What percentage would you like to tip? 15%
Leave $7.50
my problem is no matter what numbers i input, i end up getting "Leave $0.00" every single time. this is what i have written
def main():
dollars = dollars_to_float(input("How much was the meal? "))
percent = percent_to_float(input("What percentage would you like to tip? "))
tip = dollars * percent
print(f"Leave ${tip:.2f}")
def dollars_to_float(d):
str.lstrip(d)
return float(d)
def percent_to_float(p):
str.rstrip(p)
return float(p)
main()
please help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)