Loading...

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

Violeta123 avatar Violeta123 2 Точки

Wan_o_war - Programming Fundamentals Mid Exam Retake - 6 August 2019

Здравейте, може ли помощ с тази задача? Поради някаква причина изпълнява функциите със старите стойности, когато индексите са невалидни и не знам защо...

https://pastebin.com/7k1u5yLP

Условието:

Create a program that tracks the battle and either chooses a winner or prints a stalemate. On the first line you will receive the status of the pirate ship, which is a string representing integer sections separated by '>'. On the second line you will receive the same type of status, but for the warship: 

"{section1}>{section2}>{section3}… {sectionn}"

On the third line you will receive the maximum health capacity a section of the ship can reach. 

The following lines represent commands until "Retire":

  • Fire {index} {damage} – the pirate ship attacks the warship with the given damage at that section. Check if the index is valid and if not skip the command. If the section breaks (health <= 0) the warship sinks, print the following and stop the program:

"You won! The enemy ship has sunken."

  • Defend {startIndex} {endIndex} {damage} - the warship attacks the pirate ship with the given damage at that range (indexes are inclusive). Check if both indexes are valid and if not skip the command. If the section breaks (health <= 0) the pirate ship sinks, print the following and stop the program:

"You lost! The pirate ship has sunken."

  • Repair {index} {health} - the crew repairs a section of the pirate ship with the given health. Check if the index is valid and if not skip the command. The health of the section cannot exceed the maximum health capacity.

  • Status – prints the count of all sections of the pirate ship that need repair soon, which are all sections that are lower than 20% of the maximum health capacity. Print the following:

"{count} sections need repair."

In the end if a stalemate occurs print the status of both ships, which is the sum of their individual sections in the following format:

"Pirate ship status: {pirateShipSum}"

"Warship status: {warshipSum}"

 

12>13>11>20>66

12>22>33>44>55>32>18

70

Fire 2 11

Fire 8 100

Defend 3 6 11

Defend 0 3 5

Repair 1 33

Status

Retire

2 sections need repair.

Pirate ship status: 135

Warship status: 205

Тагове:
1
Python Fundamentals
Xpuck0 avatar Xpuck0 69 Точки
Best Answer

Както ти е казал колегата вече, изтриваш редове 64 и 59.

А другата грешка ти е на ред 35.  list_warship го замени с list_pirate_ship

Много коварна грешка :D

0
MartinBG avatar MartinBG 4803 Точки

Изпълнявате по два пъти Fire и Defend командите:

if command == 'Fire':
    fire()
    if fire():
        print('You won! The enemy ship has sunken.')
        break
elif command == 'Defend':
    defend()
    if defend():

 

Ако премахнете задрасканите редове от кода, задачата ще вземе 90/100 в Judge.

Test #5 не минава заради Runtime Error.

 

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