- 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

9th Mar 2022, 9:35 AM
Ayesha Ahmed
Ayesha Ahmed - avatar
15 Respuestas
+ 4
If you have tried, show us your code.
9th Mar 2022, 10:09 AM
Lisa
Lisa - avatar
+ 4
Please read the task description carefully: You need to take 2 integers as ***INPUT***. DO NOT HARD CODE THE VALUES. Get input()
9th Mar 2022, 10:13 AM
Lisa
Lisa - avatar
+ 3
num1 = 2 num2 = 8 print(num1 + num2)
9th Mar 2022, 10:12 AM
Ayesha Ahmed
Ayesha Ahmed - avatar
+ 2
Every one know who have willing to learn and started code .. Ok. What about you?? Are you tried anything?
9th Mar 2022, 9:59 AM
Jayakrishna 🇮🇳
+ 2
Yes i did try it several times but can never come up with a solution.
9th Mar 2022, 10:04 AM
Ayesha Ahmed
Ayesha Ahmed - avatar
+ 2
Thanks for your advice
9th Mar 2022, 10:14 AM
Ayesha Ahmed
Ayesha Ahmed - avatar
+ 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..
9th Mar 2022, 10:20 AM
Jayakrishna 🇮🇳
+ 2
Yes it helped
9th Mar 2022, 10:21 AM
Ayesha Ahmed
Ayesha Ahmed - avatar
+ 2
Thanks
9th Mar 2022, 10:21 AM
Ayesha Ahmed
Ayesha Ahmed - avatar
+ 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.
9th Mar 2022, 10:47 AM
Julia Marshall
+ 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.
9th Mar 2022, 4:04 PM
Lisa
Lisa - avatar
+ 1
Share your try here.. Better to Save code in playground and share link here ..
9th Mar 2022, 10:10 AM
Jayakrishna 🇮🇳
+ 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.
9th Mar 2022, 10:45 AM
Julia Marshall
0
All the lesson are lock
9th Mar 2022, 3:51 PM
TENNYSON LEBBIE
TENNYSON LEBBIE - avatar