num1 = 2.556 num2 = 2.763 num3 = .681 sum = float(num1) + float(num2) new_sum = round(num1) + round(num2) print('The sum of {0} and {1} is {2}'.format(num1, num2, sum)) print('Next, we will take the number 6 and subtract it by 5.319 to find what number is required to be added.') sub = 6 - float(sum) print('The difference is {0}'.format(sub)) sum2 = float(sum) + num3 print('If we add the {0} with {1}, we would get a sum of {2}'.format(sum, num3, sum2)) print('If using just the numbers {0} and {1}, we would not be able to get a sum of 6.'.format(num1, num2)) print('Therefore, we would have to add the following numbers: {0}, {1}, and {2} to get a sum of 6'.format(num1, num2, num3)) print('However if we round the numbers {0} and {1} we would get a sum of 6'.format(num1,num2)) print("round(2.556) + round(2.763)" + " " + "which would give us the desired sum.") print(new_sum)
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question