Input wont work with if statement if it has a space

E

eli m

Hi guys, i have a program like this: (A lot of code is not included)
run = 0
while run == 0:
raw_input("Type in a function:")
if function == "Example":
print ("Hello World!")
else:
print ("blah blah blah")

The problem is that whenever i type in example with a space after it then it prints the else statement.

My question is, how do i get it to except input with spaces?
 
E

eli m

Hi guys, i have a program like this: (A lot of code is not included)

run = 0

while run == 0:

raw_input("Type in a function:")

if function == "Example":

print ("Hello World!")

else:

print ("blah blah blah")



The problem is that whenever i type in example with a space after it then it prints the else statement.



My question is, how do i get it to except input with spaces?

oops i meant function = raw_input("Type in a function:")
 
E

emile

whenever function isn't _exactly_ "Example" the else clause executes.

If you want to catch forms of example you might try:

if function.strip().upper() == "EXAMPLE":

Emile
 
E

eli m

whenever function isn't _exactly_ "Example" the else clause executes.



If you want to catch forms of example you might try:



if function.strip().upper() == "EXAMPLE":



Emile

Thank you!
 
E

eli m

whenever function isn't _exactly_ "Example" the else clause executes.



If you want to catch forms of example you might try:



if function.strip().upper() == "EXAMPLE":



Emile

Thank you!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top