Sep-17-2017, 12:41 PM
It's difficult to say. if you revised your code, it would be helpful what revisions were made.
Given your original post:
All in all, a better way would be:
Given your original post:
if int(task) == 1: print('Select X') X = input() # This creates a string print('Select Y') Y = input() # This creates a string print('Calculating...') import time time.sleep(1) result = int(X) + int(Y) # This results in the addition of two integers print('__________') print('') print(X,'+',Y,'=',result)You are assigning strings to variables X and Y (the default action of "input()"), then in "result" you are changing them to integers. Integers are positive and negative whole numbers.
All in all, a better way would be:
if int(task) == 1: X = float(input('Select X ')) Y = float(input('Select Y ')) print('Calculating...') # Should be at beginning of file: import time time.sleep(1) result = X + Y print('__________') print('') print(X,'+',Y,'=',result) # Not a very pretty outputBe aware, however, with 'floats' you may get some surprising answers
>>> 10.1 + 20.2 30.299999999999997 >>>
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition