TORONTO KIDS COMPUTER CLUB | Aurora Monday 18:30 Python Homework 10.28.
16638
post-template-default,single,single-post,postid-16638,single-format-standard,ajax_fade,page_not_loaded,,qode-theme-ver-7.6.2,wpb-js-composer js-comp-ver-6.8.0,vc_responsive

Aurora Monday 18:30 Python Homework 10.28.

29 Oct Aurora Monday 18:30 Python Homework 10.28.

Question 1:

A store is having a sale. They’re giving 10 percent off purchases of $10 or lower, and 20 percent off purchases of greater than $10. Write a program that asks the purchase price and displays the discount (10% or 20%) and the final price.


Question 2:

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.