"Ian Egland" <echol...@gmail.com> wrote

Newbie here who can't figure out why this doesn't work:

It worked perfectly for me.

But then, maybe I expected it to do something different to
what you expected? When posting please tell us what you
expected to happen, what actually happened plus any error
messages (in full) (It also helps if you tell us what OS and
what version of Python. I'd guess from your print statements
that you are using v3 here?)

That way we can align our answers to your expectation...

start = input("Please enter the starting number.\n>")
print(type(start))
while type(start)!=float:
   start = input("Sorry, that number was invalid.\nPlease enter the
starting number.\n>")
   print(type(start))

The key thing to note here is that input() in Python v3 always returns
a string, you need to convert it to a different type. In your case you
probably want to try converting to a float:

start = float(input("Please enter the starting number.\n>"))
print(type(start))


while type(start)!=float:

Now instead of using a while loop to test the type you can expect
an exception if the type is not a float. But that's a topic for another time!

HTH,
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/l2p/

_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to