[python-nl] Eenvoudig beginners vraagje

Dorian Hoxha dorian.hoxha at gmail.com
Tue Mar 17 01:09:31 CET 2015


Hi Marc. Try this:

while True:
    try:
        x = int(raw_input("give a number:")
        break
    except (ValueError, KeyError):
        print "x must be a number, while you entered %s" % x
math.sqrt root = (x)
print x

See docs to learn more: https://docs.python.org/2/library/exceptions.html
(python2.7)



2015-03-17 0:32 GMT+01:00 Marc Stevens <marcs at ziggo.nl>:

> Hoe onderschep ik een error melding als bij de invoer van een getal als
> een letter word ingegeven?
> Bijv:
>
>
> import math
>
> x=int(raw_input(“geef een getal in”))
> wortel=math.sqrt(x)
> print x
>
> _______________________________________________
> Python-nl mailing list
> Python-nl at python.org
> https://mail.python.org/mailman/listinfo/python-nl
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-nl/attachments/20150317/0b5dc0d8/attachment.html>


More information about the Python-nl mailing list