- 1
Does anyone know the solution to this problem?
Write a program to take two integers as input and output their sum. Sample Input: 2 8 Sample Output: 10
15 odpowiedzi
+ 4
If you have tried, show us your code.
+ 4
Please read the task description carefully: You need to take 2 integers as ***INPUT***. DO NOT HARD CODE THE VALUES. Get input()
+ 3
num1 = 2
num2 = 8
print(num1 + num2)
+ 2
Every one know who have willing to learn and started code ..
Ok. What about you??
Are you tried anything?
+ 2
Yes i did try it several times but can never come up with a solution.
+ 2
Thanks for your advice
+ 2
You can take input by function :
input() #it accept input of string form. If you want integer type, then you need to convert to int as int( input() ).
Hope it helps..
+ 2
Yes it helped
+ 2
Thanks
+ 2
The solution you gave above is "hard-coded", meaning that to carry out the same function with different input you have to modify your code. The assignment was to write a flexible program to take in any two integers and print out their sum.
+ 2
TENNYSON LEBBIE Please do not post in random threads. Create your own thread when you have a question.
Go to Learn section, pick a course and start learning. The lesson unlock when you have completed all previous lessons.
+ 1
Share your try here..
Better to Save code in playground and share link here ..
+ 1
Yes, it's better to start with something like:
num1 = int( input() )
which prompts the user for the first input value and stores it as an integer in variable "num1". Do the same to get the second input integer stored, and then print the sum as you have above.
0
All the lesson are lock