Home Forums Shops Trade Avatar Inbox Games Donate
  
Not Logged In
Reply
 
Thread Tools
Default I need Python help!! #1
Not sure if I post this here buuuut I was writing a tutorial for a text based game I was making...

Then I got stuck, I've searched all over the internet but I cannot find a way to fix this.

Code:
def hello():
    '''One of the many hellos'''
    print('Hello, this is great, but lets continue.')

def hi():
    '''One of the many... his...'''
    print('Hi, ready to stop fooling around now?')

import time
time.sleep (1)

answer_is = input('Great! Now lets continue with a reasponse\ntry saying "Hello or Hi."\n>')

if answer_is in ('hello', 'hello.', 'Hello','Hello.'):
    hello()
elif answer_is in ('hi, Hi, hi., Hi.'):
    hi()
else:
    print ('Please reaspond with "Hello" or "Hi")
When you hit Enter you get "Hi, ready to stop fooling around now?" instead of "Please reaspond with "Hello" or "Hi"" and lets say you type the wrong thing it gives you "Please reaspond with "Hello" or "Hi"" then continues the tutorial.

I'd like it to be returned back to "Try saying Hello or Hi" instead of continuing, I can't seem to get it to work how I want it to :( and return doesn't work without a function but I can't get "def function" to work with if and else.

And later on I'm going to make multiple doors/paths, how would I go about multiple if elif without making a huge mess?
Also on IMVU @SaturnineCT if you add me let me know you found me on Trisphee.
Default #2
The core problem there is that you've got a single string in parentheses instead of a tuple full of strings for the "hi"'s. So instead of checking to see if the user's input is one of a list of options, it's checking to see if the user's input is contained as a substring within that string. And the empty string (which is what you get if you just press enter) is contained as a substring within ALL strings.
Mega Man: The Light of Will (Mega Man / Green Lantern crossover: In the lead-up to the events of Mega Man 2, Dr. Wily has discovered emotional light technology. How will his creations change how humankind thinks about artificial intelligence? Sadly abandoned. Sufficient Velocity x-post)

Games by Coda (updated 11/24/2019 - New game: Jigsawmino)
Art by Coda (updated 4/20/2020 - untitled original music)
Default #3
Ohh, alright, so when making If and Else lists, should I use {} then?

I changed it to {} and the reasponse for Hi no longer comes up, yay, how do I get it to return after else?
Also on IMVU @SaturnineCT if you add me let me know you found me on Trisphee.
Default #4
No, not {}, the right fix would have been to change ('Hi, hi') to ('Hi', 'hi'). You could have also used [] but that wouldn't have fixed the actual bug (but ['Hi', 'hi'] works). {} isn't the same kind of data structure; it doesn't represent a sequence and it wouldn't do what you want.
Mega Man: The Light of Will (Mega Man / Green Lantern crossover: In the lead-up to the events of Mega Man 2, Dr. Wily has discovered emotional light technology. How will his creations change how humankind thinks about artificial intelligence? Sadly abandoned. Sufficient Velocity x-post)

Games by Coda (updated 11/24/2019 - New game: Jigsawmino)
Art by Coda (updated 4/20/2020 - untitled original music)
Default #5
Ohh!! I see it now okay! I thought I had it like ('Hi', 'hi') but that's the Hellos. I get it now, thank you.

How do I get it to return to "Say Hi or Hello." after the else message?
Also on IMVU @SaturnineCT if you add me let me know you found me on Trisphee.
Default #6
Your text line is missing a ' at the end... Compare:

('Please reaspond with "Hello" or "Hi")

('Please respond with "Hello" or "Hi"')
Default #7
Sorry, I don't think I understand the question. Maybe put it in the form of a sample session demonstrating what you want to see.
Mega Man: The Light of Will (Mega Man / Green Lantern crossover: In the lead-up to the events of Mega Man 2, Dr. Wily has discovered emotional light technology. How will his creations change how humankind thinks about artificial intelligence? Sadly abandoned. Sufficient Velocity x-post)

Games by Coda (updated 11/24/2019 - New game: Jigsawmino)
Art by Coda (updated 4/20/2020 - untitled original music)
Default #8
Sorry guys, been unable to get on my laptop for awhile now. Anywhooo.

@Toho I checked my code and it's already been fixed, I'm not sure if I noticed that or if something happened in the copy or paste o_O regardless, thanks for pointing that out :)

@Coda Ermm, I'm not quite sure how to do that so I guess I'll just try to explain better?

Basically: "Great! Now lets continue with a reasponse try saying "Hello or Hi."
#Then it prompts the use to input#
|Yo
"Please reaspond with "Hello" or "Hi""
#Then it brings you back to an input so you can correct it before moving on#
|Hi
#Then the code continues#


So basically when "else" is chosen it counts as wrong and forces the player to go back, I'm actually going to need a way to send the player back for a lot of these levels, but return isn't working for me, not quite sure how to code it...
Also on IMVU @SaturnineCT if you add me let me know you found me on Trisphee.
Default #9
Ah, you're looking for a loop. Try using "while True:" to make an infinite loop, and use "break" to exit the loop or "return" to exit the function when the user puts in a response that you can work with.
Mega Man: The Light of Will (Mega Man / Green Lantern crossover: In the lead-up to the events of Mega Man 2, Dr. Wily has discovered emotional light technology. How will his creations change how humankind thinks about artificial intelligence? Sadly abandoned. Sufficient Velocity x-post)

Games by Coda (updated 11/24/2019 - New game: Jigsawmino)
Art by Coda (updated 4/20/2020 - untitled original music)
Default #10
Ohh, okay, where exactly would I put "while True:" and the "break"? I can't seem to figure that out...
Also on IMVU @SaturnineCT if you add me let me know you found me on Trisphee.
Default #11
Code:
def hello():
    '''One of the many hellos'''
    print('Hello, this is great, but lets continue.')

def hi():
    '''One of the many... his...'''
    print('Hi, ready to stop fooling around now?')

import time
time.sleep (1)

answer_is = input('Great! Now lets continue with a reasponse\ntry saying "Hello or Hi."\n>')

while True:
  if answer_is in ('hello', 'hello.', 'Hello','Hello.'):
      hello()
      break
  elif answer_is in ('hi, Hi, hi., Hi.'):
      hi()
      break
  else:
      print ('Please reaspond with "Hello" or "Hi")
Mega Man: The Light of Will (Mega Man / Green Lantern crossover: In the lead-up to the events of Mega Man 2, Dr. Wily has discovered emotional light technology. How will his creations change how humankind thinks about artificial intelligence? Sadly abandoned. Sufficient Velocity x-post)

Games by Coda (updated 11/24/2019 - New game: Jigsawmino)
Art by Coda (updated 4/20/2020 - untitled original music)
Default #12
AHHH!! OH MY GOD!!!! It keeps reprinting "Please reaspond with "Hello or hi." over and over again! It's hilarious but unplayable now, how do I make it stop?

One problem fixed, another caused eheh.
Also on IMVU @SaturnineCT if you add me let me know you found me on Trisphee.
Default #13
Oops, my bad, the `input` call should go inside there too. Wasn't paying enough attention.
Mega Man: The Light of Will (Mega Man / Green Lantern crossover: In the lead-up to the events of Mega Man 2, Dr. Wily has discovered emotional light technology. How will his creations change how humankind thinks about artificial intelligence? Sadly abandoned. Sufficient Velocity x-post)

Games by Coda (updated 11/24/2019 - New game: Jigsawmino)
Art by Coda (updated 4/20/2020 - untitled original music)
Default #14
Perfect, that was hilarious though, I'm glad the input was forgotten, it was fun to watch.

Now I just need to keep it from re-printing "Great now lets continue with a response" after "Please respond with hello or hi" and I should be able to continue with the rest of the game for a good while :D!!


Edit: WOOP! I got it all fixed up, I should be good for now :D thanks for all the help Coda!
Also on IMVU @SaturnineCT if you add me let me know you found me on Trisphee.
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All content is copyright © 2010 - 2026 Trisphee.com
FAQ | E-Mail | Terms of Service | Privacy Policy | Forum Rules
Twitter | Facebook | Tumblr
Return to top
Powered by vBulletin®