I had typed in a code for the first practice problem of adding two numbers in Python3.6 language. It wasn’t letting me submit as it raised Runtime Error. I programmed using functions to make it look better in a way. I tried running the code on PyCharm, and it worked well.
def add(n1, n2):
sum_result = n1 + n2
ch = input(“Do you want to add numbers?(y/n)”)
num1 = int(input(“Enter the first integer :”))
num2 = int(input(“Enter the second integer :”))
result = add(num1, num2)
print("The sum of the two numbers ", num1, "and ", num2, “is:”, result)
print(“See you next time!”)
This is the code.
Hi, the thing is that when you submit problems in codechef, you have to make sure that the way in which you take input and the way in which you give output should match the expected input and output which are given in the problem.
When you execute your function it does not take multiple inputs and also your funtion will print out the output before calculating the sum of the other inputs.
For example -
2 3 are inputs then in your code the inputs will be taken if they are on different lines that is 2 in one line and 3 in the below line however you need to take inputs in the same line and as also your funtion will print 5 before it takes the next input however we want all sums to be printed at the end.
I also faced similar problems when I did my first problem.
The code for the add two numbers problem in Python can be written like below.
T = int(input())
i = 0
output_list = 
A, B = map(int, input().split())
for k in output_list:
Hope it helps.