Python if statements with strings.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nick john
    New Member
    • Mar 2011
    • 4

    Python if statements with strings.

    Why does this not work? Why does this not return "good im glad". Sorry i'm a beginner.
    Code:
     x = str(input("Hello how are you?"))
        
        if x == "very good":
            print("Good Im Glad To Hear That!")
        else:
            print("I'm Sorry!")
  • dwblas
    Recognized Expert Contributor
    • May 2008
    • 626

    #2
    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.

    Comment

    • nick john
      New Member
      • Mar 2011
      • 4

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

      Comment

      • MojaveKid
        New Member
        • Sep 2007
        • 9

        #4
        you may want to try raw_input() instead of input()

        Comment

        • WooDoo
          New Member
          • Jun 2012
          • 6

          #5
          It should look like this.
          Code:
          x = raw_input('Hello how are you?')
          if x == "very good":        
                  print("Good Im Glad To Hear That!")
          else:
                  print("I'm Sorry!")

          Comment

          • Jory R Ferrell
            New Member
            • Jul 2011
            • 62

            #6
            Python 2.7 or 3.2? We need details like that since assignments can work diff between the versions.

            Comment

            • Jory R Ferrell
              New Member
              • Jul 2011
              • 62

              #7
              Ignore last message. I hadn't read all the posts. Sorry.

              Comment

              Working...