Created
November 7, 2022 22:19
-
-
Save Pinacolada64/e1d95c3231bbd20e82f48190280641e5 to your computer and use it in GitHub Desktop.
try/catch, random.choice
This file contains hidden or 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
import random | |
def ask_name(): | |
is_ok = False | |
while is_ok is False: | |
my_name = input("What is your name? ") | |
if my_name.lower() == "michelle": | |
print("You answered correctly!") | |
return my_name.title() | |
else: | |
print("Think of the person sitting to your left.") | |
class Character: | |
def __init__(self, name): | |
self.name = name | |
# just instantiating the object, fill in stuff later | |
self.armor = None | |
print(f">>> Character '{name}' instantiated.") | |
class Ally: | |
def __init__(self,name): | |
self.name = name | |
class Dict: | |
def __init__(self): | |
self.dictionary = [] | |
# def add_fish_bird: | |
# ask_name() | |
fred = Character(name=ask_name()) | |
fred.armor = random.choice(["brigandine", "leather", "plate mail", "wooden"]) | |
fred.shoe_size = 10 | |
print(f'{fred.shoe_size=} got instantiated even though not in __init__?') | |
print(f'{fred.name} has {fred.armor} armor.') | |
try: | |
print(f"{fred.unknown} property is not declared.") | |
except AttributeError: | |
print(f"Tried using 'fred.unknown' property but it's not declared.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
output: