By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,907 Members | 1,963 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,907 IT Pros & Developers. It's quick & easy.

Python if statements with strings.

P: 4
Why does this not work? Why does this not return "good im glad". Sorry i'm a beginner.
Expand|Select|Wrap|Line Numbers
  1.  x = str(input("Hello how are you?"))
  2.  
  3.     if x == "very good":
  4.         print("Good Im Glad To Hear That!")
  5.     else:
  6.         print("I'm Sorry!")
  7.  
Mar 26 '11 #1
Share this Question
Share on Google+
6 Replies


Expert 100+
P: 624
It depends on which version of Python you are using, so we can't help until we know that. Print "x" to see what it contains. Also your indentation is off, but I am assuming that is a copy/paste error and not in the program.
Mar 26 '11 #2

P: 4
I'm using python 3.2. The indentation is off because I copy and pasted it out of a program.
Thanks,
Nick
Mar 26 '11 #3

P: 9
you may want to try raw_input() instead of input()
May 22 '11 #4

P: 6
It should look like this.
Expand|Select|Wrap|Line Numbers
  1. x = raw_input('Hello how are you?')
  2. if x == "very good":        
  3.         print("Good Im Glad To Hear That!")
  4. else:
  5.         print("I'm Sorry!")
  6.  
Jun 7 '12 #5

Jory R Ferrell
P: 62
Python 2.7 or 3.2? We need details like that since assignments can work diff between the versions.
Jun 9 '12 #6

Jory R Ferrell
P: 62
Ignore last message. I hadn't read all the posts. Sorry.
Jun 9 '12 #7

Post your reply

Sign in to post your reply or Sign up for a free account.