Loading...

Във форума е въведено ограничение, което позволява на потребителите единствено да разглеждат публикуваните въпроси.

nd_nikolov avatar nd_nikolov 7 Точки

Please, hepl ! Problem sys zadacha " Travel Agency" 87/100. Kakuv e problema?

Изпит по "Основи на програмирането" – 6 и 7 юли 2019 Задача 3. Туристическа агенция

town = input()
option = input()
vip = input()
days = int(input())

price = 0

if town != 'Bansko' and town != 'Borovets' and town != 'Varna' and town != 'Burgas':
    print(f'Invalid input!')

if option != 'withEquipment' and option != 'noEquipment' and option != 'withBreakfast' and option != 'noBreakfast':
    print(f'Invalid input!')

if days < 1:
    print(f'Days must be positive number!')

if days > 7:
    days -= 1

if days > 0:
    if town == 'Bansko' or town == 'Borovets':
        if option == 'withEquipment':
            price = 100 * days
            if vip == 'yes':
                price = 100 * 0.9 * days
        elif option == 'noEquipment':
            price = 80 * days
            if vip == 'yes':
                price = 80 * 0.95 * days

    elif town == 'Varna' or town == 'Burgas':
        if option == 'withBreakfast':
            price = 130 * days
            if vip == 'yes':
                price = 130 * 0.88 * days
        elif option == 'noBreakfast':
            price = 100 * days
            if vip == 'yes':
                price = 100 * 0.93 * days

        print(f'The price is {price:.2f}lv! Have a nice time!')
Тагове:
0
Python 25/04/2020 10:43:27
MartinBG avatar MartinBG 4803 Точки

Проверката за валидност не покрива случаите с невалидни комбинации от валидни градове и пакети.

Например 'Bansko' и 'withBreakfast' е невалидна комбинация и трябва да се върне 'Invalid input!'.

 

 

Вместо дълга проверка от типа:

option != 'withEquipment' and option != 'noEquipment' and ...:

Може да се използва тази конструкция:

if not option in ( 'withEquipment', 'noEquipment', ...):

 

Поправеното решение:

town = input()
option = input()
vip = input()
days = int(input())

if days > 7:
    days -= 1

if not (town in ("Bansko", "Borovets") and option in ("noEquipment", "withEquipment",)) and not (
        town in ("Varna", "Burgas") and option in ("noBreakfast", "withBreakfast")):
    print(f'Invalid input!')
    
elif days < 1:
    print(f'Days must be positive number!')
    
else:
    if town == 'Bansko' or town == 'Borovets':
        if option == 'withEquipment':
            price = 100 * days
            if vip == 'yes':
                price *= 0.9
        elif option == 'noEquipment':
            price = 80 * days
            if vip == 'yes':
                price *= 0.95

    elif town == 'Varna' or town == 'Burgas':
        if option == 'withBreakfast':
            price = 130 * days
            if vip == 'yes':
                price *= 0.88
        elif option == 'noBreakfast':
            price = 100 * days
            if vip == 'yes':
                price *= 0.93

    print(f'The price is {price:.2f}lv! Have a nice time!')

 

0
25/04/2020 13:55:07
nd_nikolov avatar nd_nikolov 7 Точки

Благодаря много!

Това наистина го пропуснах като възможност.

1
SilviaSJ avatar SilviaSJ 3 Точки

Аз ако може да попитам, тази конструкция има ли еквивалент в java? На мен това

if (!city.equals("Bansko")|| !city.equals("Borovets") || !city.equals("Varna") || !city.equals("Burgas"))

по някаква причина ми го подчертава в жълто и пише, че ще е винаги вярно.

И това как би могло да се направи?

towns=("Bansko", "Borovets", "Varna", "Burgas")

packets=("withEquipment", "noEquipment", "withBreakfast", "noBreakfast")

В нета не знам какво точно да търся, пробвах storing multiple strings, но нещо не намирам информация, която бих могла да ползвам, сигурно защото е отвъд познанията ми до момента...  

Грешката ми в тази задача е същата, но както и да го въртя, все нещо не излиза, та търся варианти.

0
nd_nikolov avatar nd_nikolov 7 Точки

Здравей SilviaSJ,

За съжаление не разбирам от Java.

Може би е по-добре да влезеш в Java-форума за помощ.

Поздрави!

0
Wittywingstrav avatar Wittywingstrav 1 Точки

After a short time shield yourself from upsetting condition conditions with the Repel Windproof Travel Umbrella. Its structure is made of triple overlay chrome metal shaft and nine attracted fiberglass ribs that don't camping gear for sale go to front regardless, during basic tornadoes. Much basically undefined from its picture name, the umbrella has confusing water repellency.

0
asad664 avatar asad664 47 Точки

You need to take part in a contest for one corfu restaurants of the finest websites on the net. I will highly recommend this website!
 

0
raiborne avatar raiborne 4 Точки

Привет, ето и едно решение от мен като човек ползващ PHP в ежедневието, а сега се боря по Basic Python...

 

# We define the prices as a dictionary
prices = {
    "Bansko": {"noEquipment": 80, "withEquipment": 100},
    "Borovets": {"noEquipment": 80, "withEquipment": 100},
    "Varna": {"noBreakfast": 100, "withBreakfast": 130},
    "Burgas": {"noBreakfast": 100, "withBreakfast": 130},
}

# We define the VIP discounts as a dictionary
vip_discounts = {
    "no": {"noEquipment": 0, "withEquipment": 0, "noBreakfast": 0, "withBreakfast": 0},
    "yes": {"noEquipment": 5, "withEquipment": 10, "noBreakfast": 7, "withBreakfast": 12},
}

# Step 1 Read the input from the user
city = input()
package = input()
vip = input()
days = int(input())

# Step 2 validate the user input for valid input and days > 1
if city not in prices or package not in prices[city] or vip not in vip_discounts:
    print("Invalid input!")
elif days < 1:
    print("Days must be positive number!")
else:
    # Step 3 Calculate the price
    price_per_day = prices[city][package]
    discount = vip_discounts[vip][package]
    total_price = price_per_day * (days - days // 7) * (1 - discount / 100)

    # Step 4 Print the result to user
    print(f"The price is {total_price:.2f}lv! Have a nice time!")
1
Можем ли да използваме бисквитки?
Ние използваме бисквитки и подобни технологии, за да предоставим нашите услуги. Можете да се съгласите с всички или част от тях.
Назад
Функционални
Използваме бисквитки и подобни технологии, за да предоставим нашите услуги. Използваме „сесийни“ бисквитки, за да Ви идентифицираме временно. Те се пазят само по време на активната употреба на услугите ни. След излизане от приложението, затваряне на браузъра или мобилното устройство, данните се трият. Използваме бисквитки, за да предоставим опцията „Запомни Ме“, която Ви позволява да използвате нашите услуги без да предоставяте потребителско име и парола. Допълнително е възможно да използваме бисквитки за да съхраняваме различни малки настройки, като избор на езика, позиции на менюта и персонализирано съдържание. Използваме бисквитки и за измерване на маркетинговите ни усилия.
Рекламни
Използваме бисквитки, за да измерваме маркетинг ефективността ни, броене на посещения, както и за проследяването дали дадено електронно писмо е било отворено.