Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

Please Help. I would really appreciate it

+1 vote
asked Nov 3 by Eidnoxon (1,410 points)
The problem is, that i can't substract a value from a class. Example: https://onlinegdb.com/nSGKequzy. Can somebody tell me how to do it?

1 Answer

0 votes
answered Nov 3 by Peter Minarik (63,140 points)

This is because you have two instances of the You class. You always create a new instance before you'd interact with it. Instead, you should create a single instance and keep using that one. Like this:

class You:
    hp = 700
   
you = You()     # creating a single instance
you.hp -= 600   # keep using the same instance
print(you.hp)   # this instance is the same one that got the hp reduced by 600

Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...