# 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 :-

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

### # By passinng value in variable directl

`2)`

a=5

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:")   x=int(x)           # Type connversion`
`  y=input("enter value of y:")   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

total=0

i=1

while i <= num:

total+=i

i+=1

print(“total sum is:”,total)

### OUT-PUT

“C:UsersuserPython EXhelloworldvenv

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

EX/helloworld/sumOf_Multiple_Number.py”
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”

[…] How to do Sum or Addition in python […]

### 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.