I’m new to python and need help.
Here’s the ex44_4 code:
def Person_new(name, age, eyes):
person = {
"name": name,
"age": age,
"eyes": eyes,
}
def talk(words):
print(f"I am {person['name']} and {words}")
person['talk'] = talk
return person
becky = Person_new("Becky", 39, "green")
becky['talk']("I am talking here!")
I get that but I’m then asked to;
- Add a new function hit(), which makes one person hit another person.
- Give people hit points in their dict and have hit() randomly reduce each person’s hit points using random().
- Have the code run a little fight club using loops to make different people battle.
I’ve been at a week with no solution and am quite frustrated. I’m producing line after line of code running down a rabbit hole to nowhere while knowing this can be done with just a few lines… The kicker is that the next exercise introduces classes and asks me to do this again with classes, which it says is the correct way to do this and more importantly, to not do it as asked in ex44_4!!! I’m at 6s and 7s…
Here is the class ex I’m supposed to add HP and fights to:
class Person(object):
def __init__(self, name, age, eyes):
self.name = name
self.age = age
self.eyes = eyes
def talk(self, words):
print(f"I am {self.name} and {words}")
becky = Person("Becky", 39, "green")
becky.talk("I am talking here!")
I’m sure the code is rather simple but I’m just not seeing it atm. I looked at Python documentation too but it stops making sense after a few words… and there’s no examples that make sense to me. I don’t know anyone IRL who can help and I just need some simple Python to English dummy talk Thank you.