#really beginner python help
70 messages · Page 1 of 1 (latest)
Is this python 2?
Also, do you mind sending your code using a code block as photos are hard to read and people can't copy paste them
!format
Python 2? And sure.
yes=["Sure","sure", "Yes", "yes","YES"]
no=["Nah","nah","No","no","NO","Nuh uh","nuh uh"]
chooseA=["A","a"]
chooseB=["B","b"]
again=["R","r"]
def story():
print " "#this is just a space
print "Unwelcomed?"
print ""
print " "#this is just a space
answer = raw_input("You're sleeping and hear a clamorous commotion downstairs.. Do you investigate? YES or NO")
if answer in yes:
print "You creep downstairs to try and figure out what the noise is.. "
if answer in no:
print "You decide to ignore it.. but feel something ominous lurking in your room after a couple minutes."
decisionA = raw_input("As you arrive near the source of the racket you realize that it's clanking noises coming occuring from the kitchen.. What do you do? GO TO THE KITCHEN: A or GO BACK TO SLEEP: B")
if decisionA in chooseA:
print "You walk into the kitchen and see it.. a thin, elongated entity with sunken dark eyes and a gaping mouth. You remain there in fear as you look upon the entity. It stops and turns around slowly looking at you.. you and the entity stare at each other for a split second.. then it dashes towards you screeching piercingly."
yourecooked = raw_input("What do you do? RUN: A or STAY STILL: B")
if "A" or "a" in yourecooked:
print "You run as fast as you can, trying to escape this horrid creature. But deep down you know it's playing with you. You run for a mile, and get tired. Seeing on how it's prey has given up he pounces. And you get mutilated lmao.
Pt. 1/2
Pt. 2/2
'TRACKSTAR ENDING': press R to restart "
else:
if chooseB in yourecooked:
print "You get mauled to death..womp womp. USELESS ENDING: press R to restart"
restart = raw_input("Would you like to restart? Press R.")
if "R" or "r" in restart:
story()
if decisionA in chooseB:
print "You get and eerie and unsettling feeling. You go back upstairs to your room and the racket stops."
if "B" in decisionA:
print "As you lie in bed, your heavy eyelids slowly close.. but your room door slowly open creakily. A shadow darts into your closet.. SURVIVE (the entity is sensitive to light)"
if answer in no:
print "You decide to ignore it.. but feel something ominous lurking in your room after a couple minutes."
story()
Is there a reason you're using trinket and python 2? I'm asking because python 2 is no longer supported as python 3 has become the new default python version.
So if nothing is forcing you to learn python 2, it's better to learn python 3 instead as that's what will be used
raw_input and using print as a statement and not a function are indicative of python 2
Whereas python 3 uses input and print is a function
Yeah, I'm doing this as extra homework practice and we're required to use python
And I don't think we've been taught python 3 yet
Again, when one refers to python, they usually mean python 3 instead of python 2 (which you are doing)
Anyways, what seems to be the problem with your code?
So I'm trying to make a descion based story and whenever it prompts: do you want to run or stay still A or B. And I type in B it still sends the message for A
In python, strings that are non-empty are considered to have a True truth value. Additionally, when you do X or Y or X and Y, the X and Y are evaluated before the or and and. So what's happening is that because you're doing if "A" or "a" in yourecooked:, it's evaluating "A" (True) and "a" in yourecooked (may or may not be True), before "joining" them together if True or maybe is always True
Maybe cause it depends on what the value of yourecooked is
Erm, and how do I know the value?
If the user types a then "a" in yourecooked will be true right? but say if they type dhjshdjsn it won't be
It's what the user types
So I tried it and "a" isn't true
>>> bool("a")
True
The truth value of a non-empty string is True
Okay sounds good
Hi, I don't know if you'd reply can can you give a understandable explanation on what elif does?
else:
if .... :
``` is the same as ```py
elif ... :
It just allows you to add another condition to check if all the previous ones are not satisfied
Alright
Ty
So, I'm trying to stop decisionA input from running if N (no) is inputed. How do I make it so that descionA will run ONLY when Y (yes) is inputed
You'll need to explain it a bit more
Alr, when I get home
Back home (travelled). Lemme send the code
decisionX=["N","Y"]
chooseA=["A","a"]
chooseB=["B","b"]
again=["R","r"]
bool("a")
bool("b")
def story():
print " "#this is just a space
print "Unwelcomed?"
print "By NULL and NULL"
print " "#this is just a space
print "The Y or/and N should be in caps"
print " "#this is just a space
answer = input("You're sleeping and hear a clamorous commotion downstairs.. Do you investigate? [Y] or [N]")
if "Y" == answer:
print "You creep downstairs to try and figure out what the noise is.. "
elif "N" == answer:
print "You decide to ignore it.. but feel something ominous lurking in your room after a couple minutes."
elif decisionX != answer:
print "The Y or/and N should be in caps"
story()
decisionA = input("As you arrive near the source of the racket you realize that it's clanking noises coming occuring from the kitchen.. What do you do? GO TO THE KITCHEN: A or GO BACK TO SLEEP: B")
if decisionA == chooseA:
print "You walk into the kitchen and see it.. a thin, elongated entity with sunken dark eyes and a gaping mouth. You remain there in fear as you look upon the entity. It stops and turns around slowly looking at you.. you and the entity stare at each other for a split second.. then it dashes towards you screeching piercingly."
elif decisionA == chooseB:
print "You get and eerie and unsettling feeling. You go back upstairs to your room and the racket stops."
elif "B" == decisionA:
print "As you lie in bed, your heavy eyelids slowly close.. but your room door slowly open creakily. A shadow darts into your closet.. SURVIVE (the entity is sensitive to light)"
yourecooked = input("What do you do? RUN: A or STAY STILL: B")
if "A" or "a" in yourecooked:
print "You run as fast as you can, trying to escape this horrid creature.
if "R" or "r" in restart:
story()
story()
There are so many problems with that code....
Wait you didn't even implement this fix
I figured quite a bunch of things were wrong 😮💨
How do I fix this, because at this point I'm really stumped
Wait I don't use
bool (a)
To fix it?
No you don't
Did you try run it?
It will definitely be wrong
...
chooseA=["A","a"]
chooseB=["B","b"]
...
bool("a") # Doesn't do anything
bool("b") # Doesn't do anything
...
answer = input("You're sleeping and hear a clamorous commotion downstairs.. Do you investigate? [Y] or [N]")
...
elif decisionX != answer: # This should be an else
...
decisionA = input("As you arrive ...") # This is a string
if decisionA == chooseA: # decisionA is a string, chooseA is a list so they will never be equal
...
elif decisionA == chooseB: # Same thing here
...
elif "B" == decisionA:
...
yourecooked = input("What do you do? RUN: A or STAY STILL: B")
if "A" or "a" in yourecooked: # This will always be true no matter the value of yourecooked
print "You run as fast as you can, trying to escape this horrid creature.
if "R" or "r" in restart: # This string isn't even closed
story()
story()
@iron sorrel Read the comments I wrote here and see if you can fix it
Thanks a lot 😭🙏. I'll try it after work
Hey, I may or may not have just changed the whole format
did that involve re-writing it in python 3? 🙏 🙏
inshallah
import time
def intro():
print("Unwelcomed?")
time.sleep(1)
print("By ... and ...")
def question():
print("\nYou're sleeping and hear a clamorous commotion in the kitchen downstairs..")
1st part
def downstairs():
print("\nYou creep downstairs to try and figure out what the noise is..")
time.sleep(1)
choice = input("You walk into the kitchen and see it.. a thin, elongated entity with sunken dark eyes and a gaping mouth.\nYou remain there in fear as you look upon the entity. It stops and turns around slowly looking at you.. you and the entity stare at each other for a split second.. then it dashes towards you screeching piercingly.\nDo you run? [Y] or [N]:")
if choice == "Y":
print("\nYou run as fast as you can, trying to escape this horrid creature.\nBut deep down you know it's playing with you. You run for a mile, and get tired.\nSeeing on how it's prey has given up he pounces. And you get mutilated lmao.\n'TRACKSTAR ENDING': press R to restart ")
restart = input("Would you like to restart? Press R.")
if "R" in restart:
main()
time.sleep(1)
if choice == "N":
print("You get mauled to death..womp womp. USELESS ENDING: press R to restart")
restart = input("Would you like to restart? Press R.")
if "R" in restart:
main()
time.sleep(1)
def survival():
print ("You grab your flashlight to light up your surroundings.")
time.sleep(1)
choice = input("The entity is hiding in the closet, do you shine the light at him?\n[Y] or [N]:")
if choice == "Y":
print("\nIt backs away in fear and dissipates. You still feel it's presence, there is a knock in the window..")
time.sleep(1)
choice = input("Do you shine the light at it?\n[Y] or [N]:")
if choice == "Y":
print("The entity is enraged and breaks the window to attack you.\nDo you shine the flashlight at it?")
time.sleep(1)
if choice == "Y":
print("You shout 'FINAL FLASH' and a huge destructive beam of bright energy obliterates your house..\nThe entity still stands unfazed..and speaks..")
time.sleep(1)
print("'HOLLOW PURPLE', a purple ball of mass flies your way and you dissapate at the molecular level\'NAH I'D LOSE' ENDING: press R to restart")
time.sleep(1)
restart = input("Would you like to restart? Press R.")
if "R" in restart:
main()
time.sleep(1)
if choice == "N":
print("You conveniently remember a random handsign a guy taught you to use whenever you're in a pickle.\nHe says to say a secret phrase..")
time.sleep(1)
print("'WITH THIS TREASURE I SUMMON' you shout while using the handsign.. A 7ft pale monster emerges from the shadows and dissolves the entity with a backhand.")
time.sleep(1)
print("You go back to sleep because you didn't feel like questioning reality.\n'PLEASE SAVE ME' ENDING: press R to restart")
time.sleep(1)
restart = input("Would you like to restart? Press R.")
if "R" in restart:
credits()
main()
if choice == "N":
print("The entity pops out of the closet and attack you. You conveniently put up a hand sign while exclaiming\n'Domain Expansion! Crucifying Authority!\nA huge beam of light evaporates the entity")
time.sleep(1)
print("\nThe loud noise and shaking of the neighborhood alerts your neighbors and the police and reporters come to investigate the scenery.")
time.sleep(1)
print("\nThe police ask if you caused this mess.")
time.sleep(1)
choice = input("[Y] or [N]:")
if choice == "Y":
print("'Yes, I have officer.'")
time.sleep(1)
print("The officers don't belive you but they let you go.\nYOU ARE MY SPECIAL ENDING'\nPress R to Restart")
time.sleep(1)
restart = input("Would you like to restart? Press R.")
time.sleep(1)
if "R" in restart:
credits()
main()
if choice == "N":
print("'No I haven't officer.'")
time.sleep(1)
print("The officers just ask you to come in to their office to see what you witnessed.\nThey leave and the reporters coming to ask you questions")
time.sleep(1)
print("'You told us you actually fought the entity, if the entity appeared again for a rematch..would you lose?'")
time.sleep(1)
print("Nah I'd win")
time.sleep(1)
print("'HONORED ONE ENDING'\nPress R to Restart")
time.sleep(1)
restart = input("Would you like to restart? Press R.")
time.sleep(1)
if "R" in restart:
credits()
main()
def bedroom():
print("\nYou decide to ignore it.. but feel something ominous lurking in your room after az couple minutes.")
time.sleep(1)
print("As you lie in bed, your heavy eyelids slowly close.. your room door slowly open creakily. And a shadow darts into your closet..\nSURVIVE [the entity is sensitive to light]")
time.sleep(1)
survival()
def credits():
print("This is a totally not rushed story made by ... and ...")
time.sleep(1)
print("We will put this on steam, so please buy it so I can buy robux please :)")
time.sleep(1)
print("If you're unable to buy it on steam, please beg Smo to give us a 4 ;)")
time.sleep(1)
print("We hope you had fun playing this game!\nSincerely, Development Team at 'pls give us 4'\n This was truly our Jujutsu Kaisen")
time.sleep(1)
def main():
intro()
question()
while True:
decision = input("\nWill you go downstairs to investigate the sound? [Y] or [N]: ")
if decision == "Y":
downstairs()
break
elif decision == "N":
bedroom()
break
else:
print("Invalid choice. Please choose again.")
if __name__ == "__main__":
main()
Done
That's so much to read 💀
🙂
This looks way cleaner elevated! I like how the different sections are broken down into their own functions. A few points from reading the code:
- I think there are some parts where the branching might not work correctly. Look at survival(), should the second if statement be indented so that it's inside the first? I'm not sure exactly what logic you want there. It could be helpful to make use of elif when checking choice is N as it makes your code a bit easier to read (and helps prevent bugs!)
- You used
if "R" in restart. I think this should just be the same as the others and beif restart == "R"unless there was a specific reason you wanted to do that (if they typed "Don't Restart", for example, this would trigger a restart as "R" is in that string!) - This is just something extra, but you notice how the functions for each section have a lot of similarities? (printing stuff with a delay in between, then checking the user's input, then choosing the next function to call based on this input). These similarities mean that you might be able to save a lot of repetition by creating a class that can do all of this stuff, and would only need to be provided with the information unique to that section (i.e the exact text, the options, and the corresponding objects for these), you could then create an instance of this class (an object) for each section, with those details filled in. This isn't required for performance or anything but it can reduce repetition making it much easier to update the code and tweak things (think about what you'd have to do right now if you wanted to chance the 1 second delay to 2 seconds, for example)
Thank you for writing it in python 3 🙏 much nicer to read now