TORONTO KIDS COMPUTER CLUB | Aurora Wednesday 18:30 Python Practice – 08 20.10.22.
18498
post-template-default,single,single-post,postid-18498,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

Aurora Wednesday 18:30 Python Practice – 08 20.10.22.

22 Oct Aurora Wednesday 18:30 Python Practice – 08 20.10.22.

Question 1:
Create a loop between 1 to 20.

  • Print “fizz” if the number is divisible by 3
  • Print “bizz” if the number is divisible by 5
  • Print “fizzbizz” if a number is divisible by both 3 and 5.
  • Otherwise, print the number itself.

Question 2:
Continue modify the program we made in the class, so that:

  • if you chose the gun, the enemy’s hp will decrease and message box will tell how much damage caused by which of your weapon and how many enemy’s hp left.
  • if you chose the missile and did not miss the target, the enemy’s hp will decrease and message box will tell how much damage caused by which of your weapon and how many enemy’s hp left.
  • if you chose the missile but miss the target, the message box will tell you missed the target
  • if you did not choose gun or missile, the message box will tell you give up the turn
  • if enemy’s hp is lower or equal to zero, the message box will show you won and exit the loop
import random
import easygui as e
e.msgbox('Welcome to the battle field!')
mhp = 1000
ehp = 1000
while True:
    w = e.buttonbox('Your turn to fight, please choose your weapon: ',
                    choices = ['gun', 'missile'],
                    image = 'weapon.png')
    
    mDamage = 0
    if w == 'gun':
        mDamage = random.randint(50, 80)
        _______________
        e.msgbox(______________)
    elif w == 'missile':
        chance = random.randint(1, 100)
        if chance <= 40:
            mDamage = random.randint(180, 220)
            _______________
            e.msgbox(______________)
        else:
            _______________
    else:
        _______________
    ___________________
    ___________________
    ___________________
No Comments

Sorry, the comment form is closed at this time.