基本上,我试图得到一个粗略的总数在这里根据给定的输入。我不知道为什么我不能让它加上,尽管使用总和。我试着把整个事情放到一个while循环中,并将其定义为sumTotal,但什么也没做。我最终想让它显示总数,说“这是你的未贴现总数:(在这里插入总数)。你知道吗
目前,它运行和总弹出作为AAyes。这很搞笑,但不是我需要它做的。有什么建议吗?你知道吗
holidayInn = 120
showBoat = 230
mollyPitcher = 180
rideshare = 20
A = 180
B = 230
C = 120
# Declare variables
rooms = 0
hotel = 0
rideshare = "yes"
MOLLYP = "A"
SHOWB = "B"
HOLIDAY = "C"
# Greet the user
print("Hello, and welcome to our program!" + \
" Follow the prompts below to begin" + \
" planning your vacation.")
# Ask about the number of guests
party = int(input("With how many people will you be traveling?" + \
"(Larger groups may qualify for a discount!): "))
# Display discount
if 5 < party <= 8:
print("Cool! Your selection qualifies for a 10% discount" + \
"that will be applied at the end.")
elif party >= 9:
print("Cool! Your selection qualifies for a 30% discount" + \
"that will be applied at the end.")
elif party < 5:
print("Sorry, your purchase does not qualify for a discount.")
# -----------------------------------------------------------------
# Ask about the number of rooms
rooms = int(input("How many rooms will you be booking? " + \
"(please limit to 10 per transaction): ") )
# Ask about the number of nights
nights = int(input("For how many nights will you be staying? "))
# Display Hotels
print("Here are our available hotels:")
print("A. Holiday Inn: $120/night")
print("B. Showboat: $230/night")
print("C. Molly Pitcher Inn: $180/night")
# Ask which hotel
select1 = input("At which hotel will you be staying? " + \
"(Enter the capital letter that corresponds.)")
# Check validity of first selection
if select1 != MOLLYP and select1 != SHOWB and select1 != HOLIDAY:
print("Error: Enter your selection as a capital letter.")
# Ask about ridesharing
select2 = input("Will you be ultizing our ride-sharing services on your travels?" + \
" (If so, 'yes' or hit any key for no.) ")
while select2 == "yes":
print("This adds a $20 additional cost per day.")
break
sum = ((select1 * rooms * nights) + (nights * rideshare))
print(format(sum))
select1
和rideshare
是字符串,而不是数字。select1
包含用户输入的酒店名称,但您需要相应酒店的价格。您可以使用字典存储每个酒店的数字价格:下面是如何从用户输入中获取速率:
对于
rideshare
,需要根据用户输入将其设置为0或20:下面是一个有效的实现:
在rideshare中,您声明字符串“yes” 在MOLLYP中声明字符串“A”
可能你想声明如下:
select1
是值为"A"
、"B"
或"C"
的字符串。还有名为A
、B
和C
的变量。这两件事之间没有联系。select1
不会神奇地接受相应字母变量的值。你知道吗如果您想这样做,请使用字典:
或者,因为只有三种选择,所以它可能同样容易使用if/else:
相关问题 更多 >
编程相关推荐