12 May Aurora Thursday Saturday Python Homework 20.05.09.
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:
Please finish the program we made in the class so enemy will cause damage to your HP:
import random, easygui easygui.msgbox('Welcome to the battle field') name = easygui.enterbox('Please name your robot:') myHP = 1000 enHP = 1000 while True: weapon = easygui.buttonbox('Your turn to fight.\nPlease choose your weapon:', choices=['Gun', 'Missile'], image='weapon.gif') if weapon == 'Gun': myDamage = random.randint(50, 80) elif weapon == 'Missile': chance = random.randint(1, 100) if chance > 30: myDamage = 0 else: myDamage = random.randint(180, 300) else: myDamage = 0 if myDamage == 0: easygui.msgbox('You missed!!!') else: enHP -= myDamage if enHP <= 0: easygui.msgbox('Congrat!!! You won!!') break else: easygui.msgbox('You used '+weapon+' to fight, and caused '+str(myDamage)+ \ ' damages.\nThe enemy has '+str(enHP)+' HP left.', image=weapon+'.gif') # Homework starts from here enDamage = ______ myHP _________ if myHp ________ easygui.msgbox('You lost the battle!') ___________________ else: easygui.msgbox(_____________
Sorry, the comment form is closed at this time.