Python Forum
Project cus im borred
Thread Rating:
  • 2 Vote(s) - 4.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Project cus im borred
#4
It's difficult to say. if you revised your code, it would be helpful what revisions were made.

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 output
 
Be 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
Reply


Messages In This Thread
Project cus im borred - by M4J0R1C47 - Sep-16-2017, 09:10 PM
RE: Project cus im borred - by ichabod801 - Sep-16-2017, 09:22 PM
RE: Project cus im borred - by M4J0R1C47 - Sep-17-2017, 11:59 AM
RE: Project cus im borred - by sparkz_alot - Sep-17-2017, 12:41 PM
RE: Project cus im borred - by M4J0R1C47 - Sep-17-2017, 04:40 PM
RE: Project cus im borred - by ichabod801 - Sep-17-2017, 06:26 PM
RE: Project cus im borred - by M4J0R1C47 - Sep-18-2017, 04:40 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020