473,324 Members | 2,196 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Python if statements with strings.

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
6 19363
dwblas
626 Expert 512MB
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
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
you may want to try raw_input() instead of input()
May 22 '11 #4
WooDoo
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
Python 2.7 or 3.2? We need details like that since assignments can work diff between the versions.
Jun 9 '12 #6
Ignore last message. I hadn't read all the posts. Sorry.
Jun 9 '12 #7

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

Similar topics

5
by: Maurice LING | last post by:
I'm trying to toy around with PLY (python lex-yacc) by David Beazley from University of Chicago and realized that the lex module uses python raw strings. What are python raw strings and how are...
39
by: slogging_away | last post by:
Hi - I'm running Python 2.4.2 (#67, Sep 28 2005, 12:41:11) on win32, and have a script that makes numerous checks on text files, (configuration files), so discrepancies can be reported. The script...
0
by: Sundown | last post by:
Hello... This is my first time posting. One of my co workers told me this is the place to be for help on these kinds of situations. Anyhow this is what I got: I am trying to make a simple anti...
0
by: ycollet | last post by:
Hello, I'm trying to write a program to send python statements to a python server via tcp and then get back results via a tcp connection. It nearly works ... but I'm totally lost with the...
10
by: buffi | last post by:
Am I the only one that thinks that python statements should force whitespace before and after them? Right now this is not enforced and for an example these statements are valid print"hello"...
6
by: | last post by:
Hi, I used extensively python and now I find this mess with strings, I can't even reproduce tutorial examples: File "<stdin>", line 0 ^ SyntaxError: 'ascii' codec can't decode byte 0xc4 in...
0
by: | last post by:
(top posting fixed; please keep discussion on this list) --- algaba@droog.sdf-eu.org escribió: <mailman.747.1208720919.17997.python-list@python.org> Which tutorial example?
0
by: Gary Herron | last post by:
Ohad Frand wrote: There is no way you can consider 'elif', 'else', 'except', and 'from' statements. However, as someone pointed out, the kwlist from the keyword module is the closest thing we...
0
by: Ohad Frand | last post by:
Hi Thanks a lot for your reply I think the main uses for it is to study the language and to see that I didn't miss anything else or that something is changed from one version to another. The...
4
by: Mohd Khan | last post by:
For example, can we execute the following script a = 4 b = 3 k = 4 * c c = a + b print k without getting a name error(since c is defined in the 4th line but called for in the 3rd line) i.e....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.