Професионална програма
Loading...
+ Нов въпрос
ItsMomchilS avatar ItsMomchilS 2 Точки

Basic Syntax, Conditional Statements and Loops - Exercise

Здравейте. Имам въпрос относно задача номер 10. Cristmas Spirit.

Решавам задачите повторно за да опресня знанията си, но се натъкнах в judge на 50/100 въпреки, че на тестовите решения отговора ми пасва. Ако може да погледнете и да ми кажете къде бъркам. Благодаря предварително!

 

Eто как съм го написал аз:

quantity = int(input())
days = int(input())

christmas_spirit = 0
ornament_set = 0
tree_skirt = 0
tree_garlands = 0
tree_lights = 0

for day in range(1, days + 1):

    if day % 2 == 0:
        ornament_set += quantity
        christmas_spirit += 5

    if day % 3 == 0:
        tree_skirt += quantity
        tree_garlands += quantity
        christmas_spirit += 13

    if day % 5 == 0:
        tree_lights += quantity
        christmas_spirit += 17

    if day % 10 == 0:
        christmas_spirit -= 20
        tree_skirt += 1
        tree_garlands += 1
        tree_lights += 1

    if day == 11:
        quantity = quantity + 2

    if days == 10:
        christmas_spirit -= 30

ornament_price = ornament_set * 2
tree_skirt_price = tree_skirt * 5
tree_garlands_price = tree_garlands * 3
tree_lights_price = tree_lights * 15

total_cost = ornament_price + tree_garlands_price + tree_lights_price + tree_skirt_price

print(f"Total cost: {total_cost}")
print(f"Total spirit: {christmas_spirit}")
Тагове:
0
Python
svephoto avatar svephoto 288 Точки

Здравей,

 

Би ли дал и условието на задачата?

0
ItsMomchilS avatar ItsMomchilS 2 Точки

* Christmas Spirit 
It's time to get in a Christmas mood. You have to decorate the house in time for the big event, but you have limited days to do so.
You will receive allowed quantity for one type of decoration and days left until Christmas day to decorate the house.
There are 4 types of decorations and each piece costs a price
Ornament Set – 2$ a piece
Tree Skirt – 5$ a piece
Tree Garlands – 3$ a piece
Tree Lights – 15$ a piece
Every second day you buy an Ornament Set quantity of times and increase your Christmas spirit by 5.
Every third day you buy Tree Skirts and Tree Garlands (both quantity of times) and increase your spirit by 13.
Every fifth day you buy Tree Lights quantity of times and increase your Christmas spirit by 17. If you have bought Tree Skirts and Tree Garlands at the same day you additionally increase your spirit by 30.
Every tenth day you lose 20 spirit, because your cat ruins all tree decorations and you have to rebuild the tree and buy one piece of tree skirt, garlands and lights. That is why you are forced to increase the allowed quantity with 2 at the beginning of every eleventh day.
Also if the last day is a tenth day the cat decides to demolish even more and ruins the Christmas turkey and you lose additional 30 spirit.
At the end you must print the total cost and the gained spirit.
Input / Constraints
The input will consist of exactly 2 lines:
quantity – integer in range [1…100]
days – integer in range [1…100]
Output
At the end print the total cost and the total gained spirit in the following format:
"Total cost: {budget}"
"Total spirit: {totalSpirit}"

Examples
Input    Output
3      Total cost: 558
20    Total spirit: 156

0
svephoto avatar svephoto 288 Точки

Така, значи проверката за 11-тия ден трябва да бъде в началото на цикъла и да е

if day % 11 == 0:

а не

if day == 11:

понеже проверяваш за всеки 11-ти ден (11, 22, 33 и т. н.), а не просто за самия 11-ти ден и край.

Същото важи и за проверката за 10-тия ден, при която трябва да намалим christmas_spirit с 30:

if day % 10 == 0:

а не

if day == 10:

Тази конкретна проверка се изважда извън/след цъкъла.

И освен това трябва да добавим и още една проверка вътре в цикъла (ще видиш къде съм я сложил като отвориш линка с кода по-долу):

if day % 3 == 0 and day % 5 == 0:
    christmas_spirit += 30

Това са нещата, ето кода за 100/100 (ползвал съм твоя код): https://pastebin.com/3z2qQKwP.

 

Успех!

0
24/02/2020 22:20:34