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….
a=5
b=10 print(“total sum of a and b is:”,a+b)
total+=i
Table of Contents
Syntax and Examples :
# Simply Adding
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
# Here type conversing and taking input
#from user
total=0
i=1
while i <= num:
total+=i
i+=1
print(“total sum is:”,total)
OUTPUT
“C:UsersuserPython EXhelloworldvenv
Scriptspython.exe” “C:/Users/user/Python
EX/helloworld/sumOf_Multiple_Number.py”
1) sum is 9
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
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
total sum is: 15
Process finished with exit code 0


Python Comment  Creating a Comment  multiline comment  example
 Python Comment  Creating a Comment  multiline comment  example
 Python Dictionary Introduction  Why to use dictionary  with example
 How to do Sum or Addition in python
 Python Reverse number
 find common number in python
 addition of number using for loop and providing user input data in python
 Python Count char in String
 Python Last Character from String
 Python Odd and Even  if condition
 Python Greater or equal number
 Python PALINDROME NUMBER
 Python FIBONACCI SERIES
 Python Dictionary  Items method  Definition and usage
 Python Dictionary  Add data , POP , popitem , update method
 Python Dictionary  update() method
 Delete statement , Looping in list In Python
 Odd and Even using Append in python
 Python  Simple Odd and Even number
How to do Sum or Addition in python
One comment on “How to do Sum or Addition in python”
[…] How to do Sum or Addition in python […]