Code for Adding Two Numbers in Python (Shell / Console Based)

numb1=input(“Enter first number “)

numb2=input(“Enter second number “)

x=int(numb1)

y=int(numb2)

z=x+y

print(‘Sum of ‘,x, ‘ and ‘, y, ‘ is ‘, z)

 

User is asked to enter two numbers by invoking input function. The numerical values entered by the user will be assigned to two string variables numb1 and numb2 respectively. The values that are in string format in numb1 and numb2 variables are type casted into integer numbers by invoking int function. The values after being converted into integer format are assigned to the two int variables x and y respectively. Addition of integer values in variables x and y is done and the total is assigned to the third variable, z. The addition of two numbers in z is displayed on the screen by invoking the print function

 

Leave a Comment