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.

Can anyone help turn this pseudocode into working code in python 3?Also Please use functions.

+3 votes
asked Feb 10, 2023 by Rex (360 points)
edited Feb 11, 2023 by Rex
print welcome message input name
print message about the magical jungle
print message about creatures the user will face print message about goal of the game
set health to 20
print description of the three-horned beetle 
print “Would you like to fight or run?”
set choice to input 
if choice is “fight”
    print “Your options are to set a trap, use your bare hands, or use a stick set weapon to input
        if weapon is “set a trap”
            print “You have defeated the beetle!” health = health + 50
        if weapon is “use bare hands”
            print “You have lost to the beetle. Game over.” end game
        if weapon is “use a stick”
            print “You have beaten the beetle!” health = health + 50
        else
            print “Not a valid option.” end game
else
    print “You have outrun the beetle! You are safe now.” health = health + 30
print health
print description of purple-winged dinosaur
print “You can redeem your health points for a sword or a pair of wings.” 
set option to input
if option is “pair of wings” 
    health = health – 20 
    print health
    print “You now have wings and can fly!” 
if option is “sword”
    health = health – 20 
    print health
    print “You now have a sword!”
print “Would you like to attack the dinosaur with the sword or fly away?” 
set choice to input
if choice is “attack with sword”
    strikes = random number between 3 and 7 for i = 0 to strikes
        print “The dinosaur struck you!” 
        health = health – 10
        print health
        print “You struck the dinosaur!”
    if health > 0
        print “You survived the attack!”
    else
        print “You have been mortally wounded. Game over.” end game
if choice is “fly away”
    print “The dinosaur eventually overtakes you. Game over.” end game
print “You have reached the invisible force field surrounding the edge of the set secret to random number between 10 and 99
set count to 0
set guess to input
while count < 7 and guess does not equal secret 
    if guess > secret
        print “too high”
    if guess < secret
        print “too low” 
    set guess to input 
    count = count + 1
if guess = secret
    print “Congratulations! You have disarmed the force field and have won the
else
    print “Sorry. The force field has not been disarmed, and you have lost the

2 Answers

+1 vote
answered Feb 11, 2023 by Douglas Pinto do Nascimento (270 points)
# Welcome message
name = input("Please enter your name: ")
print("Welcome, " + name + ", to the magical jungle.")

# Message about the jungle
print("You have entered a mystical jungle filled with mythical creatures.")

# Message about creatures
print("You will face various creatures such as the three-horned beetle and the purple-winged dinosaur.")

# Message about the goal of the game
print("The goal of the game is to reach the edge of the jungle and disarm the invisible force field.")

# Set health to 20
health = 20

# Description of the three-horned beetle
print("The three-horned beetle is a formidable opponent with its sharp horns and tough exoskeleton.")

# Ask to fight or run
choice = input("Would you like to fight or run? ")

# Check choice
if choice == "fight":
    # Ask for weapon
    weapon = input("Your options are to set a trap, use your bare hands, or use a stick. Choose your weapon: ")
    if weapon == "set a trap":
        print("You have defeated the beetle! ")
        health += 50
    elif weapon == "use bare hands":
        print("You have lost to the beetle. Game over.")
        exit()
    elif weapon == "use a stick":
        print("You have beaten the beetle! ")
        health += 50
    else:
        print("Not a valid option.")
        exit()
else:
    print("You have outrun the beetle! You are safe now. ")
    health += 30

# Print health
print("Your health is now: " + str(health))

# Description of the purple-winged dinosaur
print("The purple-winged dinosaur is a fierce flying beast with razor sharp claws.")

# Redeem health points
option = input("You can redeem your health points for a sword or a pair of wings. Choose your option: ")
if option == "pair of wings":
    health -= 20
    print("Your health is now: " + str(health))
    print("You now have wings and can fly!")
elif option == "sword":
    health -= 20
    print("Your health is now: " + str(health))
    print("You now have a sword!")

# Attack or fly away
choice = input("Would you like to attack the dinosaur with the sword or fly away? ")
if choice == "attack with sword":
    # Random number of strikes
    import random
    strikes = random.randint(3, 7)
    for i in range(strikes):
        print("The dinosaur struck you! ")
        health -= 10
        print("Your health is now: " + str(health))
        print("You struck the dinosaur! ")
    if health > 0:
        print("You survived the attack!")
    else:
        print("You have been mortally wounded. Game over.")
        exit()
elif choice == "fly away":
    print("The dinosaur eventually overtakes you. Game over.")
    exit()

# Invisible force field
import random
secret = random.randint(10, 99)
count = 0
guess = int(input("You have reached the invisible force field surrounding the edge of the jungle. Guess the secret number between 10 and 99: "))
while count < 7 and guess != secret:
    if guess > secret:
        print("Too high.")
    elif guess < secret:
        print("Too low.")
    guess = int(input("Try again: "))
    count += 1
if guess == secret:
    print("Congratulations! You have disarmed the force field and have won the game.")
else:
    print("Sorry. The force field has not been disarmed, and you have lost the game.")
+1 vote
answered Feb 11, 2023 by i212680 Muhammad Younas Sohail (170 points)
import random

def welcome_message(name):
    # prints a welcome message with the user's name
    print("Welcome, " + name + "!")

def jungle_message():
    # prints a message about the magical jungle
    print("You have entered a magical jungle filled with dangerous creatures.")

def creature_message():
    # prints a message about the creatures the user will face
    print("You will face many dangerous creatures in your journey.")

def goal_message():
    # prints a message about the goal of the game
    print("Your goal is to reach the invisible force field at the edge of the jungle.")

def set_health():
    # sets the initial health to 20
    return 20

def beetle_description():
    # prints a description of the three-horned beetle
    print("A three-horned beetle blocks your path. It is known to be very dangerous.")

def fight_or_run():
    # asks the user if they want to fight or run
    return input("Would you like to fight or run?\n")

def beetle_fight(health):
    # function for fighting the beetle
    weapon = input("Your options are to set a trap, use your bare hands, or use a stick. Choose your weapon:\n")
    if weapon == "set a trap":
        print("You have defeated the beetle!")
        health += 50
    elif weapon == "use bare hands":
        print("You have lost to the beetle. Game over.")
        return -1
    elif weapon == "use a stick":
        print("You have beaten the beetle!")
        health += 50
    else:
        print("Not a valid option.")
        return -1
    return health

def beetle_run(health):
    # function for running away from the beetle
    print("You have outrun the beetle! You are safe now.")
    health += 30
    return health

def redeem_health(health):
    # function for redeeming health points for a sword or a pair of wings
    option = input("You can redeem your health points for a sword or a pair of wings. Choose an option:\n")
    if option == "pair of wings":
        health -= 20
        print("You now have wings and can fly!")
    elif option == "sword":
        health -= 20
        print("You now have a sword!")
    return health

def dinosaur_attack(health):
    # function for attacking the dinosaur
    choice = input("Would you like to attack the dinosaur with the sword or fly away?\n")
    if choice == "attack with sword":
        strikes = random.randint(3, 7)
        for i in range(strikes):
            print("The dinosaur struck you!")
            health -= 10
            print("You struck the dinosaur!")
        if health > 0:
            print("You survived the attack!")
        else:
            print("You have been mortally wounded. Game over.")
            return -1
    elif choice == "fly away":
        print("The dinosaur eventually overtakes you. Game over.")
        return -1
    return health

def force_field():
    # function for disarming the invisible force field
    secret = random.randint(10, 99
commented Feb 12, 2023 by Rex (360 points)
It does not work
commented Feb 13, 2023 by Rex (360 points)
The code does not work
commented Feb 15, 2023 by Rex (360 points)
Thank you so much it finally worked!
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.
...