#๐Ÿ”’ can someone please review my code and lmk why it isn't working? i genuinely don't know what to do

104 messages ยท Page 1 of 1 (latest)

fervent rose
#

hi, im trying to write a short, 8 outcomes choose your own adventure text game in python, but i keep running into errors. at this point, idk what the errors are anymore, so I wanted to ask if someone could please review the whole thing and lmk what isnt working. thanks.

#Importing a python library function
import random

# Defining values
answer = input("START [Y/N]")
answer2 = input("[A OR B]")
answer3 = input("[C OR D?]")


# Starting the game
def start():
    if answer.upper().strip() == "Y":
        print("You are at a social event hosted by the Culture & Technology Community club, drinking a cup of juice, and see someone who catches your eye. You stare for a disturbingly long time, feeling attracted by them. What do you do?")
        print(list(["A) Go Up To Them", "B) Leave The Event."]))
    else:
        print("Sorry you don't wanna play : ( !")
        
# First 2 user choices - Pick between A or B, and detect if "N" was answered in previous function
def act1():
    if answer.upper().strip() == "N":
        start()

        if answer2.upper().strip() == "A":
            print("You walk up to the person, but now what do you do?")
            print(list(["C) Give them a rose", "D) Introduce yourself"]))
        elif answer2.upper().strip() == "B":
            print("You feel anxious and flustered, watching the person, wondering what life could have been. You go to sit in a corner, finishing your juice, wishing you had social skills.")
            start()
        else: 
            print("Not an option, sorry!")
            start()```
fervent boneBOT
#

@fervent rose

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

fervent rose
#
# Next 2 choices - Pick between C or D, and detect if "N" was answered in previous function
def act2():
    if answer.upper().strip() == "N":
        start()
        
        if answer3.upper().strip() == "C":
            print("You do not have a rose, would you like to get one?")
        elif answer3.upper().strip() == "D":
            (print("You walk up to the person, tightening the grasp of your juice cup, feeling your heart accelerate as you think of what to say. The person turns around to look at you. What do you say?"))
            print(list(["E) Hey there, how's it going?", "F) I couldn't help but notice you glowing the room", "G) Hey! What brings you to the CTC?", "H) This is a bit awkward, but would you like to go on a date with me?"]))
            pickup_lines = input(list("[E, F, G, or H?]"))
            
            #If player selects to introduce themselves, the output is randomly selected regardless of input
            if pickup_lines.upper().strip() in ("E", "F", "G", "H"):
                hit = "You got the date, congratulations!"
                fail2 = "They plainly told you they were not interested. You have failed to get the date."
                chance = [fail2, hit]
                choice = (random.choice(chance))
                print(choice)
                start()
        else:
            print("Not an option, sorry!")
            act1()```
#
# Function to determine what happens on whether or not the player wants to get a rose - in both cases it is a loss/failure of the game
def act3():
    if answer.upper().strip() == "N":
        start()
        
        rose = input("[Y/N]")
        if rose.upper().strip() == "Y":
            print("You walk around the room, finding a decorative pot of roses. You pick one and bring it back to the person. They appreciate the gesture, but find it weird, and excuse themselves. You have failed to get the date.")
            start()
        elif rose.upper().strip() == "N": 
            fail = print("Awkward. They noticed your staring, and feeling embarassed, you go back to just sitting all alone in a corner, enjoying your juice, fantasising what could have been, which you hate your brain for.")
            print(fail)
            start()
        else:
            print("Not an option, sorry!")
            act2()

    
#Order of play    
start()
act1()
act2()
act3()```
#

sorry i cant post it in one text cuz discord limitations : (

late mango
fervent rose
#

by errors i mainly mean the code just isnt working properly
like when I run it, and get to act1(), it doesn't print the text. it just skips steps. idk if my sequencing is off or smth else.

#

i wish it was a syntax thing that's easier

late mango
#

remember you shouldn't ever assign a variable to a print

fervent rose
#

right

late mango
#

A lot of issues you're running into then are likely due to how you've nested your functions

#

look at the order you try and call your functions

#

but in act1, you're also calling start()

fervent rose
#

yea but it's not even running the function correctly i think

late mango
#

you're also getting input outside of any function

#

It looks like you might have skipped past some basic python knowledge and jumped right into something a bit complex

fervent rose
late mango
#

I'd really recommend taking a step back and properly learning how to implement functions

fervent rose
#

but i rlly feel it shouldnt be

#

the only thing i havent dealt with before is sequencing functions

late mango
#

building a branching narrative adventure is a lot harder than it might seem

fervent rose
#

i can tell

#

and idk how to fix this cuz my assignment is due soon
and ive been spending hours fixing errors that create new ones

late mango
#

nesting function calls is really your major problem here

fervent rose
#

everything im using is what we were taught too so im prob just failing or smth

late mango
#

you're creating function "depth" which can lead to many hard-to-trace issues

fervent rose
#

prob looked up the wrong thing

late mango
#

honestly using functions here is making this more difficult

fervent rose
#

i mean i tried coding this without the use of functions
it made me want to rip my head out so i went with functions order

late mango
#

since you now need to juggle the scope of your responses

fervent rose
#

yea but when i went without functions
using if, elif, and else statements, i kept running into issues i couldnt solve

#

the google search said functions is best for narrative games like this

#

and at first it worked

#

now it's failing me again xD

late mango
#

they can be useful, sure, but you need a pretty strong understanding of them

fervent rose
#

can tell

late mango
#

the major solve you'll need to implement here is how you handle repeating actions

#

you shouldn't repeat calling functions to cause something to trigger again

#

you need to use loops to handle this

fervent rose
#

loops i see

#

but arent loops list specific?

late mango
#

no

#

there's two types of loops

#

for and while

#

you want while loops here

fervent rose
#

oh

late mango
#

while loops are conditional loops

fervent rose
#

wait where i would i implement them tho

late mango
#
while True:
    response = input("Enter the room?")
    if response.lower() in ('y', 'yes'):
        break

print("You have entered the room")

fervent rose
#

is it in the function definition or to sequence them?

#

oh that

late mango
#

try running this example

#

your start function doesn't really lead to anything

fervent rose
#

oh?

late mango
#

the other thing you can make use of here is return to get data out of the function

fervent rose
#

it's supposed to print text tho

late mango
#

yes that's ok

#

but it doesn't ask for any input

fervent rose
fervent rose
late mango
#

you're asking for input() globally which has no relation to the functions

#

you shouldn't really have any code outside of the functions other than the code that calls them

fervent rose
#

..

#

oh

#

yea i put those outside cuz i got tired

late mango
#

there's a lot to cover here about functions

fervent rose
#

they werent working inside the function

late mango
#

which is why I suggested learning them properly

fervent rose
late mango
#

.rp defining functions

stable ferryBOT
#

Here are the top 5 results:

Using Python Optional Arguments When Defining Functions
MATLAB vs Python: Why and How to Make the Switch
What Are Python Asterisk and Slash Special Parameters For?
Python's reduce(): From Functional to Pythonic Style
fervent rose
late mango
#

Check out the 2nd link here

fervent rose
#

ill do that but for now ill just figure out a way to make a quick cheap game
idc anymore lmao

late mango
#

rock/paper/scissors is a pretty common beginner friendly game to code

fervent rose
#

ill look into it thanks

#

it's just i need 4 layers with 8 outcomes
idk how to do that but ill yolo it i dont have a choice lmao

late mango
#

what does that even mean?

fervent rose
#

it means i need to have 4 things happen in the game

#

with each leading to 2 outcomes

late mango
#

that's quite vague

#

what's a "thing"?

fervent rose
#

so say
jimmy enters forest:
dies by bear or continues

jimmy continues:
finds papers on trees, does jimmy
take them or run away

run away jimmy gets
caught by bear or falls in ravine

take them jimmy lives on

smth like that

#

a decision tree basically

#

im gonna code this actually lmao

late mango
#

I'd do it without functions then

#

or just one large function

#

instead of trying to split it into acts

fervent rose
#

yea it's just my previous idea got too complicated
so i resorted to functions because everything else kept failing and it was getting late

#

so now ill try to make smth SUPER simple with if and elif statements only

late mango
#

design it first before you write any code

#

come up with your ideas on paper

#

it will make it a lot simpler to code

fervent rose
#

I did
the coding was just not working lmao

fervent rose
#

!close

fervent boneBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.