Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

get sum from x to y in python

# From user input, using lambda
# pass string directly to lambda
print((lambda s: sum(range(int(s[0]), int(s[1])+1)))(input().split()))
# or, convert string to list then pass into lambda
print((lambda s: sum(range(s[0], s[1]+1)))(list(map(int, input().split()))))
# input: 1 100
# output: 5050
# Or, simply, from variables
a, b = 1, 100
print(sum(range(a, b+1)))
Comment

PREVIOUS NEXT
Code Example
Python :: pandas select columns by index 
Python :: set background colour tkinter 
Python :: select rows where column value is in list of values 
Python :: int to string python 
Python :: how to change username of a bot using discord.py 
Python :: multiple values in python loop for x,y 
Python :: install python 3.6 on centos 
Python :: how to add mouse button in pygame 
Python :: check input in python 
Python :: reverse an array python 
Python :: concatenate dataframes pandas without duplicates 
Python :: The Python path in your debug configuration is invalid. 
Python :: change column name pandas 
Python :: python tkinter change color of main window 
Python :: fizzbuzz python solution 
Python :: distplot with plotly 
Python :: how download youtube video in python 
Python :: how to get user id from username discord.py 
Python :: import gensim 
Python :: python function to scale selected features in a dataframe pandas 
Python :: py declare type list 
Python :: how to convert cost to float in python 
Python :: import time in python 
Python :: django custom save method 
Python :: square all elements in list python 
Python :: how to know the length of a dataset tensorflow 
Python :: hardest python questions 
Python :: python insertion sort 
Python :: string remove everything after character python 
Python :: rotate point around point python 
ADD CONTENT
Topic
Content
Source link
Name
6+1 =