[Swlug] Quick Python question

Rhys Sage rhys_sage at yahoo.com
Thu Feb 3 00:57:15 UTC 2022


I'm partly using a book to learn Python but mostly having a bash at it using the Pocket Reference by Mark Lutz. 
I'm trying to work out whether NumberOne is numeric and each time I run it I get a problem when the condition falls on False.
if ((NumberOne.isnumeric == False) and (NumberTwo.isnumeric == False)):    print("Retard - I asked for numbers")    print (NumberOne.isnumeric())    print (NumberTwo.isnumeric())
This is the True output....
0.3 x 0.8 =  0.24
Gimme Number 1 109
Gimme Number 2 123and the aardvaark says  13407.0end
When I enter non numerical numbers I get this output....Traceback (most recent call last):
  File "<ipython-input-2-7bebae7324b7>", line 1, in <module>    runfile('/home/rhys/Documents/Python/sexy.py', wdir='/home/rhys/Documents/Python')
  File "/usr/lib/python3/dist-packages/spyder_kernels/customize/spydercustomize.py", line 827, in runfile    execfile(filename, namespace)
  File "/usr/lib/python3/dist-packages/spyder_kernels/customize/spydercustomize.py", line 110, in execfile    exec(compile(f.read(), filename, 'exec'), namespace)
  File "/home/rhys/Documents/Python/sexy.py", line 26, in <module>    NumberOne = float(NumberOne)
ValueError: could not convert string to float: 'nonumber'
I'll probably have more equally clueless questions as I continue.
Rhys Sage
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.lug.org.uk/pipermail/swlug/attachments/20220203/75d4ceaf/attachment.htm>


More information about the Swlug mailing list