Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Add multiple numbers
- # A small beginner python program
- # The program uses list as data structure and
- # sum() function to add multiple number from list
- """
- Example-
- python3 calc.py
- Enter number separated via comma:1,2,3
- output: 6
- """
- user_input = input('Enter number separated via comma:')
- str_numbers= user_input.split(',') # splitting string numbers by comma and creating a list
- int_numbers=[]
- for items in str_numbers:
- #converting all the string nums to int nums
- int_numbers.append(int(items))
- print(sum(int_numbers))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement