TORONTO KIDS COMPUTER CLUB | Markham Saturday 9:30 Python Homework 11.16.
16730
post-template-default,single,single-post,postid-16730,single-format-standard,ajax_fade,page_not_loaded,,no_animation_on_touch,qode-theme-ver-7.6.2,wpb-js-composer js-comp-ver-6.10.0,vc_responsive

Markham Saturday 9:30 Python Homework 11.16.

20 Nov Markham Saturday 9:30 Python Homework 11.16.

Question :

You are trying to destroy the enemy spaceship which is protected by the energy shell. However, you only have 2 missiles left. Each missile can cause a random damage between 1 to 150. Assume the enemy’s energy shell can provide 100 protection. Write a program:

  • Using random.randint() to calculate each missile’s damage and print them out.
  • If the damage of first missile greater than enemy’s protection, print enemy is destroyed after first missile launch
  • If the first missile can not destroy the enemy. The protection of the enemy energy shell is deducted by the damage of first missile. And you are going to launch the second missile
  • if the second missile’s damage is greater than the protection left over, print enemy is destroyed after second missile launch
  • if you did not destroy the enemy after two missiles, print the enemy is escaped.

sample output 1:

missile 1: 59
missile 2: 102
enemy is destroyed after first missile launch

sample output 2:

missile 1: 45
missile 2: 32
the enemy is escaped

No Comments

Sorry, the comment form is closed at this time.