问题描述
这么多问题..目前,我的代码正在计算成本,成人和儿童的数量.如果用户仅输入1个孩子,我希望它打印孩子,而不是孩子.
So many questions.. At the moment my code is calculating the cost, number of adults and children. If the user only inputs 1 child I want it to print child, not children.
serviceType = input("Would you like (M)edium or (R)are steak?")
if serviceType == "r":
rare = float((noChild * rare) * DISCOUNT) + (noAdult * BASIC)
print("That is " + formatCurrency(rare) + " for rare choice for " + str(noAdult) + " adults and " + str(noChild) + " children. Enjoy!")
输出显示这是$-2名成人和1名儿童的罕见选择.我需要说这是$-对于1个成人和1个孩子的罕见选择.
The output showsThis is $-- for rare choice for 2 adults and 1 children.I need it to say "This is $-- for rare choice for 1 adults and 1 child.
我认为我需要放一个
if noChild == 1
在某处声明,但不确定将其添加到何处?
statement somewhere, but not sure where to add it in?
我也使用相同格式的代码来计算中",因此我无法将句子更改为child,否则,如果用户输入2,则将是2 child.我希望我已经正确地解释了自己?
I also have the same format of code to calculate "medium" so I can't change the sentence to child, otherwise if the user enters 2 it will be 2 child. I hope I have explained myself properly?
谢谢
推荐答案
您可以这样编写打印语句:
You can write the print statement like this:
print("That is " + formatCurrency(rare) + " for rare choice for " + str(noAdult) +
(" adult" if noAdult==1 else " adults") + " and " + str(noChild) +
(" child" if noChild==1 else " children") + ". Enjoy!")
这篇关于复数,如果语句为python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!