How to do Sum or Addition in python

How to do Sum or Addition in python

you can do addition in different way like directly by adding to two or more  number . you can also take user input value . if you take user input value then you have to do type conversion because by default it take string value . Other way is by using looping and many other way are there….

Syntax and Examples :-

# Simply Adding

1) print(“sum is”,4+5)

# By passinng value in variable directl



b=10 print(“total sum of a and b is:”,a+b)

# Addinng by taking Input from User

3) x=input("enter value of x:")
int(x) # Type connversion
  y=input("enter value of y:")
int(y) # Type connversion
 z=x+y                # Adding X and Y
 print("sum of x and y is:",z)# Result of Sum

# Addition using While loop
4) num=int(input(“enter number:”))

# Here type conversing and taking input

#from user
while i <= num:

print(“total sum is:”,total)


“C:UsersuserPython EXhelloworldvenv

Scriptspython.exe” “C:/Users/user/Python

1) sum is 9
2) total sum of a and b is: 15
3) enter value of x:7
enter value of y:8
sum of x and y is: 15
4) enter number:5
total sum is: 15

Process finished with exit code 0

How to do Sum or Addition in python

Have any Question or Comment?

One comment on “How to do Sum or Addition in python

Leave a Reply

Your email address will not be published. Required fields are marked *

Domain & free Hosting


You have successfully subscribed to myprogrammingschool

There was an error while trying to send your request. Please try again.

My Programming School will use the information you provide on this form to be in touch with you and to provide updates and marketing.