0
import random
user = input("You reconize this creture. The feared BaLaKe. Its weakness is 'rock', 'paper',''scissors' Are you willing to challenge him in a battle of Rock Paper Scissors? (ENTER)" )
print("ROARRRRRRRRRRRRRRRRRRR!!!!!")

Below is the function I want to loop when userhealth and dragonhealth <= 0. I want it to keep asking for input for rock, paper, or scissors and go through the conditions.

def fight(userhealth,dragonhealth):
 dragon = random.choice(["r","p","s"])
 user=input("Rock(r), Paper(p) or Scissors(s): ").lower()
 print(dragon)
 if user==dragon:
     print("You both missed your attacks. Bruh ;-;")
 elif is_win(user,dragon):

        dragonhealth-=20 
        print("You hit BaLaKe! 20 DMG Done!!! :) ") 
        print("Your health: "+str(userhealth )+" HP")
        print("BaLaKe\'s health: "+str(dragonhealth )+" HP") 
        
     else: 
      print("Ow! You got hit by BaLake. -20 HP :( ")     
      userhealth-=20 
      print("Your health: "+str(userhealth )+" HP")
      print("BaLaKe\'s health: "+str(dragonhealth )+" HP")
    
    def is_win(player,opponent):
        if (player=="r" and opponent=="s") or (player=="s" and opponent=="p") or (player=="p" and opponent=="r"):
         return True
    
    
    fight(100,100)
       

    
DrippyDino
  • 37
  • 8

3 Answers3

2

Do you want this ?

import random
user = input("You recognize this creture. The feared BaLaKe. Its weakness is 'rock', 'paper',''scissors' Are you willing to challenge him in a battle of Rock Paper Scissors? (ENTER)" )
print("ROARRRRRRRRRRRRRRRRRRR!!!!!")
def fight(userhealth,dragonhealth):

  while(userhealth>0 and dragonhealth>0):

    dragon = random.choice(["r","p","s"])
    user=input("Rock(r), Paper(p) or Scissors(s): ").lower()
    print(dragon)
    if user==dragon:
        print("You both missed your attacks. Bruh ;-;")
    elif is_win(user,dragon):

            dragonhealth-=20 
            print("You hit BaLaKe! 20 DMG Done!!! :) ") 
            print("Your health: "+str(userhealth )+" HP")
            print("BaLaKe\'s health: "+str(dragonhealth )+" HP") 
            
    else: 
        print("Ow! You got hit by BaLake. -20 HP :( ")     
        userhealth-=20 
        print("Your health: "+str(userhealth )+" HP")
        print("BaLaKe\'s health: "+str(dragonhealth )+" HP")
        
    def is_win(player,opponent):
        if (player=="r" and opponent=="s") or (player=="s" and opponent=="p") or (player=="p" and opponent=="r"):
            return True


fight(100,100)
quamrana
  • 37,849
  • 12
  • 53
  • 71
Mete Korucu
  • 113
  • 12
1

Try the following code:

import random

user = input("You reconize this creture. The feared BaLaKe. Its weakness is 'rock', 'paper',''scissors' Are you willing to challenge him in a battle of Rock Paper Scissors? (ENTER)" )
print("ROARRRRRRRRRRRRRRRRRRR!!!!!")
dragonhealth = 100
userhealth = 100

def fight(userhealth,dragonhealth,choice):
    dragon = random.choice(["r","p","s"])
    print(dragon)
    if choice==dragon:
        print("You both missed your attacks. Bruh ;-;")

    elif is_win(choice,dragon):
        dragonhealth-=20 
        print("You hit BaLaKe! 20 DMG Done!!! :) ") 
        print("Your health: "+str(userhealth )+" HP")
        print("BaLaKe\'s health: "+str(dragonhealth )+" HP") 
        
    else: 
        print("Ow! You got hit by BaLake. -20 HP :( ")     
        userhealth-=20 
        print("Your health: "+str(userhealth )+" HP")
        print("BaLaKe\'s health: "+str(dragonhealth )+" HP")
    return userhealth,dragonhealth
        
def is_win(player,opponent):
    if (player=="r" and opponent=="s") or (player=="s" and opponent=="p") or (player=="p" and opponent=="r"):
        return True

while (userhealth>0 or dragonhealth>0):
    choice=input("Rock(r), Paper(p) or Scissors(s): ").lower()
    userhealth,dragonhealth = fight(userhealth,dragonhealth,choice)

if userhealth>0:
    print("You won! ")
elif dragonhealth>0:
    print("You lost! ")

Explanation: Sets the original healths at the start. Sets up a while loop to check if either of them have less than 0 health. Subtracts and updates the health when you lose/win. Declares a winner at the end!

0
  1. Use While loop for repeating the game util someone gets 0 HP.

  2. I created a function to terminate the game when someone is at 0 HP. See it

    enter code here

import random

user_health = 100  # used underscore snake case love:)
dragon_health = 100  # I initialized both variables outside


def fight(user_health, dragon_health):  # according to PEP8 I guess. we shouldn't use shadow names. Still,not a big deal
    dragon = random.choice(["r", "p", "s"])
    user = input("Rock(r), Paper(p) or Scissors(s): ").lower()
    print(dragon)

    if user == dragon:
        print("You both missed your attacks. Bruh ;-;")
        return user_health, dragon_health
    elif is_win(user, dragon):

        dragon_health -= 20
        print("You hit BaLaKe! 20 DMG Done!!! :) ")  #
        print("Your health: " + str(user_health) + " HP")
        print("BaLaKe\'s health: " + str(dragon_health) + " HP")
        return user_health, dragon_health

    else:
        print("Ow! You got hit by BaLake. -20 HP :( ")
        user_health -= 20
        print("Your health: " + str(user_health) + " HP")
        print("BaLaKe\'s health: " + str(dragon_health) + " HP")
        return user_health, dragon_health


def is_win(player, opponent):
    if (player == "r" and opponent == "s") or (player == "s" and opponent == "p") or (
            player == "p" and opponent == "r"):
        return True


# this function terminates game when someone is at 0 HP and prints output
def game_terminator(user_health, dragon_health):  # I continued with the shadow names to avoid confusion
    if user_health == 0:
        print("Dragon killed you!")
        return False
    elif dragon_health == 0:
        print("Thrashed dragon to dealth! YOU WON!")  # Nerd outputs :)
        return False
    else:
        return True


game_is_on = True
# Use while loop for game to run until someone gets 0 HP
while game_is_on:  # game_is_on is a boolean variable
    user_health, dragon_health = fight(user_health, dragon_health)
    game_is_on = game_terminator(user_health, dragon_health)

  # Thank Me :)