Loading...

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

Kiril1914 avatar Kiril1914 2 Точки

Затруднение със задача 10. Bread Factory

Привет

От два часа вече дебъгвам задача с която съм се заел, а именно:  10. Bread Factory от  Lists Basics - Exercise 

Judge ми дава 88/100. Преразгледах логиката, операторите, както и възможност за синтактични грешки.

Някой може ли да ми съдейства? 

Благодаря

 

Ето моят Код:    https://pastebin.com/T64AHJLN

 

 

                                                                                          Условието на задачата: 

Bread Factory

  1. You have initial energy 100 and initial coins 100.
  2. You will be given a string representing the working day events.
  3. Each event is separated with '|' (vertical bar): "event1|event2| … eventN"

Each event contains an event name or an ingredient and a number, separated by a dash ("{event/ingredient}-{number}")

  • If the event is "rest":
    • You gain energy (the number in the second part). Note: your energy cannot exceed your initial energy (100). Print: "You gained {gained_energy} energy.".
    • After that, print your current energy: "Current energy: {current_energy}.".

 

  • If the event is "order":
    • You've earned some coins (the number in the second part).
    • Each time you get an order, your energy decreases by 30 points.
      • If you have the energy to complete the order, print: "You earned {earned} coins.".
      • Otherwise, skip the order and gain 50 energy points. Print: "You had to rest!".

 

  • In any other case, you have an ingredient you should buy. The second part of the event contains the coins you should spend.

 

  • If you have enough money, you should buy the ingredient and print:

"You bought {ingredient}."

  • Otherwise, print "Closed! Cannot afford {ingredient}." and your bakery rush is over.

If you managed to handle all events through the day, print on the following 3 lines:

"Day completed!"

"Coins: {coins}"

"Energy: {energy}"

Examples

Input

Output

rest-2|order-10|eggs-100|rest-10

You gained 0 energy.

Current energy: 100.

You earned 10 coins.

You bought eggs.

You gained 10 energy.

Current energy: 80.

 

Day completed!

Coins: 10

Energy: 80

order-10|order-10|order-10|flour-100|order-100|oven-100|order-1000

You earned 10 coins.

You earned 10 coins.

You earned 10 coins.

You bought flour.

You had to rest!

Closed! Cannot afford oven.

 

Тагове:
0
Python
MartinBG avatar MartinBG 4803 Точки

Променете 49-ти ред от:

if coins > exspense:

На:

if coins >= exspense:

Иначе, има някои излишни неща в решението. Ето съкратен вариант:

import sys

entrance = input().split("|")
 
energy = 100
coins = 100
 
for event in entrance:
    split = event.split("-")
 
    if split[0] == "rest":
        energy_from = int(split[1])

        if 100 - energy < energy_from:
            energy_from = 100 - energy

        energy += energy_from
        print(f"You gained {energy_from} energy.")
        print(f"Current energy: {energy}.")
    elif split[0] == "order":
        earn = int(split[1])
 
        if energy >= 30:
            coins += earn
            energy -= 30
            print(f"You earned {earn} coins.")
        else:
            energy += 50
            print("You had to rest!")
    else:
        expense = int(split[1])
        if coins >= expense:
            print(f"You bought {str(split[0])}.")
            coins -= expense
        else:
            print(f"Closed! Cannot afford {str(split[0])}.")
            sys.exit()
 
print("Day completed!")
print(f"Coins: {coins}")
print(f"Energy: {energy}")

 

1
Можем ли да използваме бисквитки?
Ние използваме бисквитки и подобни технологии, за да предоставим нашите услуги. Можете да се съгласите с всички или част от тях.
Назад
Функционални
Използваме бисквитки и подобни технологии, за да предоставим нашите услуги. Използваме „сесийни“ бисквитки, за да Ви идентифицираме временно. Те се пазят само по време на активната употреба на услугите ни. След излизане от приложението, затваряне на браузъра или мобилното устройство, данните се трият. Използваме бисквитки, за да предоставим опцията „Запомни Ме“, която Ви позволява да използвате нашите услуги без да предоставяте потребителско име и парола. Допълнително е възможно да използваме бисквитки за да съхраняваме различни малки настройки, като избор на езика, позиции на менюта и персонализирано съдържание. Използваме бисквитки и за измерване на маркетинговите ни усилия.
Рекламни
Използваме бисквитки, за да измерваме маркетинг ефективността ни, броене на посещения, както и за проследяването дали дадено електронно писмо е било отворено.