Addition of Number using for loop
In this program addition of numbers using for loop, we will take the user input value and we will take a range from 1 to input_num + 1. Using for loop, we will sum all the values.
num=int(input("enter number:"))
total=0
for i in range(1,num+1):
total+=i
i+=1
print("total sum is:",total)
Sum of all input number in Python
n=input("enter number: ").split(',')
total=0
for i in range(len(n)):
total+=int(n[i])
i+=1
print(total)
Output:
C:\Users\Pramod\PycharmProjects\pythonProject\venv\Scripts\python.exe C:/Users/Pramod/PycharmProjects/pythonProject/main.py
enter number: 1,2,3,4,5
15
Process finished with exit code 0
A simple way for Addition by using def in Python
def add():
return "sum of these two number is:",11+99
print(add())
Output:
C:\Users\Pramod\PycharmProjects\pythonProject\venv\Scripts\python.exe C:/Users/Pramod/PycharmProjects/pythonProject/main.py
enter number: saa
('sum of these two number is:', 110)
Process finished with exit code 0
Recommended Post:
- Python Hello World Program
- 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 the 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 the condition
- Python Greater or equal number
- Python PALINDROME NUMBER
- Python FIBONACCI SERIES
- Python Dictionary | Items method | Definition and usage
- Python Dictionary | Add data, POP, pop item, update method
- Python Dictionary | update() method
- Delete statement, Looping in the list In Python
- Odd and Even using Append in python
- Python | Simple Odd and Even number
Get Salesforce Answers