0

Hopefully you don't mind the foreign language in prints. Also I started python last week so sorry if the code is bad and unpractical.

Okay so what im trying to do is have a player health and player damage multiplied by a random number between 1-10 and then subtract the result from the enemy health (the easy health variable) and then do the same the other way around (playerhealth-easydamage*random) And then if the enemy's or players health reaches 0 a message about the winner gets printed out. I haven't gotten to that part yet. My problem is i only either got File stdin syntax error or the out put is literally "None"

def fightgame():
    Player_Health=150
    Player_Damage=7
    Easy_Health=120
    Easy_Damage=5
    for _ in range(5):
        x= random.randint(1,10)
        def Easy_PT():
            Pdamage = x * Player_Damage
            Easy_Health - Pdamage
            if Easy_Health != 0: 
                print ("Vyhral si.")
            else:
                print ("Boss má " +Easy_Health+ "životov.")
        def Easy_FT():
            Edamage = x * Easy_Damage
            Player_Health - Edamage
            if Player_Health != 0:
                print ("Prehral si.")
            else:
                print ("Máš " +Player_Health+ "životov.")
print(fightgame())


if __name__ == "__main__":
    fightgame()

totmom
  • 11
  • 4

1 Answers1

-1

Your post may get flagged as a bad questions, but dont mind it for now...

Its not easy to completly understand your question, but this is what I've changed to make it run how I think you want it to work.

It printed None because you were printing a function that doesnt return anything. Printing works everywhere, so you can do it where ever you want. Here you can read more about functions and print and return.

import random


def fightgame():
    Player_Health = 150
    Player_Damage = 7
    Easy_Health = 120
    Easy_Damage = 5
    for _ in range(5):
        x = random.randint(1, 10)

        Pdamage = x * Player_Damage
        Easy_Health -= x * Pdamage
        if Easy_Health <= 0:
            print("Vyhral si.")
        else:
            print("Boss má " + str(Easy_Health) + " životov.")

        Edamage = x * Easy_Damage
        Player_Health -= Edamage
        if Player_Health <= 0:
            print("Prehral si.")
        else:
            print("Máš " + str(Player_Health) + " životov.")


if __name__ == "__main__":
    fightgame()

Have fun trying it out.

bitflip
  • 3,436
  • 1
  • 3
  • 22
  • 1
    thank you, u kind of understood what i meant, finally got the code to do what i wanted after a little tweaking, no idea how to upload the code in the comment so im not gonna paste it here. Thank you for your help tho it helped a lot – totmom Sep 22 '22 at 18:36