Python Forum
Can someone please help me with my code?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Can someone please help me with my code?
#1
import time

answer_a = ["A", "a"]
answer_b = ["B", "b"]
answer_c = ["C", "c"]
yes = ["Y", "y", "Yes", "yes"]
no = ["N", "n", "No", "no"]
required = "Please use only A, B, or C"

print("please type 'start()' to start the game!")

def start():
    print("""\n
\n
After passing out from partying the entire night,
you wake up in a very dark and dense forest. Your head's spinning uncontrollably and your heart is racing.
behind you, you hear a very grotesque sound coming closer, and closer.
You look behind you and it's a wild boar with red eyes and foam spewing from it's mouth. Quickly, you: """)
    print("\nA. Grab a nearby stick to defend yourself \nB. stay still \nC. Run\n")
    choice = input(">>>")
    if choice in answer_a:
        option_stick()
    if choice in answer_b:
        dead()
    if choice in answer_c:
        option_run()
    else:
        print(required)
        start()


def option_stick():
    print("""\n
\n
\n
You whack the wild boar with a stick, and it hits the ground,
it gets back up on it's feet and starts to charge you! you: """)
    print("\nA. Climb a nearby tree \nB. hit it again! \nC. Kick it")
    choice1 = input(">>>")
    if choice1 in answer_a():
        option_climb()
    if choice1 in answer_b():
        option_hit()
    if choice1 in answer_c():
        option_kick()
    else:
        print(option_stick())

def option_climb():
    print("a")

def option_hit():
    print("b")

def option_kick():
    print("c")




def option_run():
    print("""\n
\n
\n
You decided to run from the wild boar,
but you end up at the face of a cliff, You: """)




def dead():
    print("You died, would you like to restart?: ")
    restart = input()
    if restart in yes:
        start()
    else:
        start()
Reply
#2
First, allow me to be the one to initiate you by passing on some information that will help you out here in the forum. Welcome, BTW.

First, there are tags to put in your message that make your code look like this:

### Put a "[ python]" at the beginning and a "[/python ]" minus the spaces at the end of code to maintain the ###indentation and stuff.

import time

answer_a = ["A", "a"]
answer_b = ["B", "b"]
answer_c = ["C", "c"]
yes = ["Y", "y", "Yes", "yes"]
no = ["N", "n", "No", "no"]
required = "Please use only A, B, or C"

print("please type 'start()' to start the game!")
Secondly, what is it you want help with? Specific questions are much more likely to get answered. Fear not. Every new person get's told these same things. myself included.

So maybe edit your message and ask a question that will give you an answer you can use.

"Can someone please help me with my code?" is too general and the answer is "yes", dozens of people here "can".

Cheers
Reply
#3
I would recommend looking at my text adventure tutorial. It explains a better way to handle this sort of game than the if/else structure you seem to be working with.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#4
Thank you guys! that helped a lot
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020