Issues with conditionals


#1

Can anybody tell me what’s wrong with my code? The link below is a picture of my code and the console.


#2

Consider this,

mod = raw_input("Maybe it'll print")       // you enter 0

if mod == 0:
  print mod
else:
  print "it didn't work"

the output is “it didn’t work”

Now, consider this,

mod = raw_input("Maybe it'll print")       // you enter hello

if mod == "hello":
  print mod
else:
  print "it didn't work"

the output is “hello”

Why? What’s the unique difference between the two? What kind of data are we dealing with?


#3

The difference is that zero is an integer and ‘hello’ is a string. So that means raw_input must store the input as a string. Thanks for the help.


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.