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 someone please fix this??

0 votes
asked Mar 2 by Christopher Bartholf (280 points)
import time
print("Welcome to the jungle, a place where magical creatures abound.") time.sleep(2)
print("These creatures are not friendly, and to make it out of the jungle aliv time.sleep(2)
print("Good luck!") time.sleep(2)
health = 20print("You first encounter a giant three-horned beetle! It is black, slimy, an time.sleep(2)
print("The beetle starts charging toward you!")
choice = input("Would you like to fight or run?")
if choice == "fight":
    weapon = input("Your options are to set a trap, use your bare hands, or use a stick.")
    if weapon == "set a trap":
        print("You have captured the beetle!")
        health = health + 50
    if weapon == "use bare hands":
        print("You have lost to the beetle. Game over.")
        exit()
    if weapon == "use a stick":
        print("You have killed the beetle!")
        health = health + 50
else:
    print("You have outrun the beetle and are safe!")
    health = health + 30
print("You have",health,"health points.") time.sleep(2)
print("Uh-oh! A huge dinosaur with purple wings is flying right towards you! It has sharp, pointy teeth and looks hungry!")
time.sleep(2)
print("You can redeem your health points for a sword or a pair of wings.")
time.sleep(2)
option = input("Would you like a sword or wings?")
if option == "wings":
    health = health – 20
    print("You can fly!")
    time.sleep(1)
    print("You now have", health, "health points.")
    time.sleep(2)
    print("The dinosaur is flying after you!")
    time.sleep(2)
    print("The dinosaur has overtaken you. Game over.")
    exit()
if option == "sword":
    health = health - 20
    print("You now have a sword!")
    time.sleep(1)
    print("You now have", health, "health points.")
    time.sleep(2)
    print("Get ready for the fight!")
    time.sleep(2)
    strikes = random.randint(3, 6)
    for i in range(strikes):
        print("The dinosaur strikes you!")
        health = health - 10
        time.sleep(1)
        print("You now have", health, "health points.")
        time.sleep(2)
        if health = 0:
            print("You have been mortally wounded. Game over.")
            exit()
        print("You strike the dinosaur!")
        time.sleep(2)
    print("Finally, the fight is over, and you have survived the attack!")
    time.sleep(2)

2 Answers

+1 vote
answered Mar 2 by Peter Minarik (22,620 points)

If you copy someone else's code, you should make sure you copy it correctly. Also, you should make sure that you have the right to use their code...

Fixing it is as simple as running (includes compiling) it and fixing where the compiler says something went wrong.

This should be (more or less) all right now:

import time
import random

print("Welcome to the jungle, a place where magical creatures abound.")
time.sleep(2)
print("These creatures are not friendly, and to make it out of the jungle alive.")
time.sleep(2)
print("Good luck!")
time.sleep(2)
health = 20
print("You first encounter a giant three-horned beetle! It is black, slimy, and angry.")
time.sleep(2)
print("The beetle starts charging toward you!")
choice = input("Would you like to fight or run?")
if choice == "fight":
    weapon = input("Your options are to set a trap, use your bare hands, or use a stick.")
    if weapon == "set a trap":
        print("You have captured the beetle!")
        health = health + 50
    if weapon == "use bare hands":
        print("You have lost to the beetle. Game over.")
        exit()
    if weapon == "use a stick":
        print("You have killed the beetle!")
        health = health + 50
else:
    print("You have outrun the beetle and are safe!")
    health = health + 30
print("You have",health,"health points.")
time.sleep(2)
print("Uh-oh! A huge dinosaur with purple wings is flying right towards you! It has sharp, pointy teeth and looks hungry!")
time.sleep(2)
print("You can redeem your health points for a sword or a pair of wings.")
time.sleep(2)
option = input("Would you like a sword or wings?")
if option == "wings":
    health = health - 20
    print("You can fly!")
    time.sleep(1)
    print("You now have", health, "health points.")
    time.sleep(2)
    print("The dinosaur is flying after you!")
    time.sleep(2)
    print("The dinosaur has overtaken you. Game over.")
    exit()
if option == "sword":
    health = health - 20
    print("You now have a sword!")
    time.sleep(1)
    print("You now have", health, "health points.")
    time.sleep(2)
    print("Get ready for the fight!")
    time.sleep(2)
    strikes = random.randint(3, 6)
    for i in range(strikes):
        print("The dinosaur strikes you!")
        health = health - 10
        time.sleep(1)
        print("You now have", health, "health points.")
        time.sleep(2)
        if health == 0:
            print("You have been mortally wounded. Game over.")
            exit()
        print("You strike the dinosaur!")
        time.sleep(2)
    print("Finally, the fight is over, and you have survived the attack!")
    time.sleep(2)
commented Mar 9 by Paige Timmeny (100 points)
just word of warning to the next time you do this, you put time.sleep()  inside the print, just try to add it on another line, not on the same as the print().
+1 vote
answered Mar 9 by Костадин Клемов (260 points)
I think it is because when you go to fight the beetle, you used multiple if statements in the code.

Maybe it would work if you used the elif statement instead of the if statement (Only do it after the first if).
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.
...