Write a program to add two numbers with user input

Write a program to add two numbers with user input





Program

# create variable that Store input values
x = input('enter first number: ')            
y = input('enter second number: ')

sum = x + y ;

# show the  output
print(“sum of num1 and num2 is ",sum)


Output
 

    enter first number: 10 
    enter second number: 10 
    sum of num1 and num2 is 1010



in above program the sum is 10 10 , input function is take a string value of variable x and y so we convert the input value in string to int 


Example
# convert the input that Store integer values in variable x and y
x = int(input('enter first number: '))
y = int(input('enter second number: '))

sum = x + y ;

# show the  output
print(“sum of num1 and num2 is ",sum)

Output 

enter first number: 10 
enter second number: 10 
sum of num1 and num2 is 20
Post a Comment (0)
Previous Post Next Post