Last active
January 25, 2018 10:42
-
-
Save DaraDDB1/48b33fdc0cc1cfcb0118be63efb50544 to your computer and use it in GitHub Desktop.
Classes and Objects
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Monster: #this makes the monster a class | |
health = 15 #shows that the health is equal to 15 | |
def gethit(self): #defines the function | |
self.health = self.health-1 #this shows that if you use gethit, itll reduce the health by 1 | |
print("Ouch! My health is now " + str((self.health)) #it will print this statement | |
def sayhealth(self): | |
print("My health is " +str((self.health)) #this will print your health if you type it | |
Brian = Monster() #tells you that Brian is a monster | |
choice = input("CHOOSE YOUR WEAPON! SWORD OR PILLOW") #this gives you the option to choose a weapon | |
if choice == "sword": #if ypu choose the option swords | |
print("You have chosen the swords.") #it prints this statement | |
Brian.gethit() #and it will hit brian | |
elif choice == "pillow": #if you choose pillow | |
print("You have chosen the weakest weapon. No health effect.") #it will print this | |
#but there will be no effect on brians health because a pillo cant do anything | |
else: | |
print("THAT WASN'T AN OPTION!") #if you type anything other than pillow or sword it will print this | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment