1.

Solve : python help?

Answer»

Hello.
I've got a simple problem i can't find a solution to, although i know it's something very simple.

Okay how can i return an error message when having the user input something, but they dont enter anything and just press enter, i'm thinking along the lines of like:
CODE: [Select]X = input("Type something: ")
if x == null:
print("you didn't enter anything")
But yeah i need to know what you would type to signify like nothing/no data. Or perhaps there is a way to do it via except statements.

Could anyone shed some light on this for me?Hmmm. Last week it was Java, this week it's Python.  I have risen to my level of incompetence.

Google helped a lot here SINCE my Python skills are less than zero.

Code: [Select]x = raw_input("Enter something: ")
if x == "":
  print "You entered nothing"
else:
  print "You entered:", x;

RUNS under Python 2.6.1.1 if that MAKES a difference.

Good luck.  Quote from: Sidewinder on August 19, 2011, 06:37:33 AM

Hmmm. Last week it was Java, this week it's Python.  I have risen to my level of incompetence.

Google helped a lot here since my Python skills are less than zero.

Code: [Select]x = raw_input("Enter something: ")
if x == "":
  print "You entered nothing"
else:
  print "You entered:", x;

Runs under Python 2.6.1.1 if that makes a difference.

Good luck. 


x=="" is one way... but here's a more "Pythonic" one , whatever that means
Code: [Select]....
if not x:
  ....


Discussion

No Comment Found