Переменная select1 содержит строку. Когда вы умножаете строку на целое число n, вы повторяете строку n раз. Пример ("A" * 4 = "AAAA").
Вам необходимо сопоставить введенную строку с соответствующей переменной (A, B или C). Рекомендую создать словарь с ценами отеля:
#Get rid of these:
#A = 180
#B = 230
#C = 120
#Use this instead:
hotel_prices = {
'A': 180,
'B': 230,
'C': 120
}
После того, как вы подтвердите ввод, вы можете получить цену int, используя словарь:
# Check validity of first selection
if select1 != MOLLYP and select1 != SHOWB and select1 != HOLIDAY:
print("Error: Enter your selection as a capital letter.")
select1 = hotel_prices[select1]
У вас та же проблема с переменной rideshare. Сначала вы задаете для него значение int (rideshare = 20), а затем меняете его на строку (rideshare = 'yes'). Избавьтесь от второго объявления, если не будете его использовать. Вы можете проверить опцию rideshare, используя оператор if:
if select2 == "yes":
print("This adds a $20 additional cost per day.")
else:
rideshare = 0
Есть и другие улучшения, которые можно сделать здесь, но, надеюсь, это решит проблему, с которой вы столкнулись. Вот полный код:
#holidayInn = 120
#showBoat = 230
#mollyPitcher = 180
#rideshare = 20
#Get rid of these
#A = 180
#B = 230
#C = 120
hotel_prices = {
'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.")
select1 = hotel_prices[select1]
# 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 statement is not necessary here:
#while select2 == "yes":
# print("This adds a $20 additional cost per day.")
# break
#
# Use an if statement:
if select2 == "yes":
print("This adds a $20 additional cost per day.")
else:
rideshare = 0
sum = ((select1 * rooms * nights) + (nights * rideshare))
print(format(sum))