Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

get sum of a range from user input

# 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 :: python to create pandas dataframe 
Python :: read excel file in python 
Python :: how to import include in django 
Python :: draw bounding box on image python opencv 
Python :: remove spaces in string python 
Python :: select 2 cols from dataframe python pandas 
Python :: input multiple values in python 
Python :: how to hide a widget in tkinter python 
Python :: tqdm python 
Python :: change size of plot python 
Python :: how to delete json object using python? 
Python :: dense rank in pandas 
Python :: how to get a hyperlink in django 
Python :: extract pdf with python 
Python :: try open file 
Python :: django radio button 
Python :: Python Tkinter SpinBox Widget 
Python :: how to delete a column from a dataframe in python 
Python :: python how to change back to the later directory 
Python :: python print numbers 1 to 10 in one line 
Python :: numpy round to int 
Python :: Taking a list of strings as input, our matching function returns the count of the number of strings whose first and last chars of the string are the same. Also, only consider strings with length of 2 or more. python 
Python :: python check if int 
Python :: python webbrowser close tab 
Python :: get just filename without extension from the path python 
Python :: is there a way to skip the first loop on a for loop python 
Python :: concat dataframes 
Python :: argparse required arguments 
Python :: python curve fitting 
Python :: how to disconnect wifi using python 
ADD CONTENT
Topic
Content
Source link
Name
4+2 =