[Swlug] Quick Python question
Rhys Sage
rhys_sage at yahoo.com
Thu Feb 3 10:30:50 UTC 2022
Thanks Ian and Colin,
I did get an unexpected result in that it won't handle decimals but that's part of the learning process. I'm guessing that it's checking for numbers only and that there might be an isdecimal. I'll have to look later. It's 5:30am and I have to rush off to work.
runfile('/home/rhys/Documents/Python/sexy.py', wdir='/home/rhys/Documents/Python')0.3 x 0.8 = 0.24
Gimme Number 1 c
Gimme Number 2 cRetard - I asked for numbersFalseFalseend
runfile('/home/rhys/Documents/Python/sexy.py', wdir='/home/rhys/Documents/Python')0.3 x 0.8 = 0.24
Gimme Number 1 6.6
Gimme Number 2 6Retard - I asked for numbersFalseTrueend
runfile('/home/rhys/Documents/Python/sexy.py', wdir='/home/rhys/Documents/Python')0.3 x 0.8 = 0.24
Gimme Number 1 7
Gimme Number 2 6and the aardvaark says 42.0end
#!/usr/bin/env python3# -*- coding: utf-8 -*-"""Created on Mon Sep 27 16:52:01 2021
@author: Rhys"""#Declare variablesNumberOne = 0.3NumberTwo = 0.8NumberThree = 0
#subroutines
#actual codeNumberThree = NumberOne*NumberTwoprint ("0.3 x 0.8 = ", NumberThree)NumberOne = input("Gimme Number 1 ")NumberTwo = input("Gimme Number 2 ")
#if ((NumberOne.isnumeric != False) and (NumberTwo.isnumeric != False)):if not (NumberOne.isnumeric() and NumberTwo.isnumeric()): print("Retard - I asked for numbers") print (NumberOne.isnumeric()) print (NumberTwo.isnumeric())else: NumberOne = float(NumberOne) NumberTwo = float(NumberTwo) NumberThree = NumberOne * NumberTwo print ("and the aardvaark says ", NumberThree)print ("end")
Rhys Sage
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.lug.org.uk/pipermail/swlug/attachments/20220203/9e81947b/attachment-0001.htm>
More information about the Swlug
mailing list