Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
PROGRAMS ON LIST & TUPLE TYPE:
#WRITE A PYTHON PROGRAM TO DEMONSTRATE WORKING OF LIST IN PYTON AND
IT'S OPERATIONS
mylist=[1,2,3,4]
new=[10,11]
newlist=[15,12,13,12]
#length
print('length of mylist is:',len(mylist))
#accessing
print('The first element is:',mylist[0])
print('The second element is:',mylist[1])
print('The third element is:',mylist[2])
print('The fourth element is:',mylist[3])
#slicing
print('mylist[0:3]',mylist[0:3])
print('mylist[:2]',mylist[:2])
print('mylist[1:]',mylist[1:])
print('mylist[-3:-1]',mylist[-3:-1])
print('mylist[::-1]',mylist[::-1])
#append
mylist.append(5)
print('After append,the list is:',mylist)
#insert
mylist.insert(1,6)
print('After insert,the list is:',mylist)
mylist.append(new)
print('After append,the list is:',mylist)
#extend
mylist.extend(newlist)
print('After extend,the list is:',mylist)
#accessing
print('The sixth element is:',mylist[6])
print('The seventh element is:',mylist[7])
print('The eight element is:',mylist[8])
print('The sixth of zero index element is:',mylist[6][0])
#remove
newlist.remove(12)
print('after remove ,the list is:',newlist)
#del
del newlist[2]
print('after delete ,the list is:',newlist)
#pop
print('before pop() ,the list is:',mylist)
mylist.pop()
print('after pop() ,the list is:',mylist)
print('before pop(6) ,the list is:',mylist)
mylist.pop(6)
print('after pop(6) ,the list is:',mylist)
#clear
print('before clear() ,the list is:',new)
new.clear()
print('after clear() ,the list is:',new)
#count
l1=[1,2,2,3,3,4,2]
print('count(2) is:',l1.count(2))
#index
print('index(2) is:',l1.index(2))
#sort
mylist.sort()
print('Sorting is:',mylist)
mylist.sort(reverse=True)
print('Sorting is:',mylist)
#reverse
mylist.reverse()
print('Reverse list is:',mylist)
#copy and assigning
l1=[1,2,3]
l2=l1
print(l1,l2)
l1[0]=4
print(l1,l2)
l2=l1.copy()
print(l1,l2)
l1[0]=5
print(l1,l2)
l2=list(l1)
print(l1,l2)
l1[0]=6
print(l1,l2)
#max,min & sum
print('Max of mylist is:',max(mylist))
print('Min of mylist is:',min(mylist))
print('sum of mylist is:',sum(mylist))
#all,any
val1=[1,2,3,4,0]
print('all:',all(val1))
print('any:',any(val1))
val2=[1,2,3,4,5]
print('all:',all(val2))
print('any:',any(val2))
val3=[None,None,None,False]
print('all:',all(val3))
print('any:',any(val3))
#enumerate
branch=['ece','eee','cse']
obj=enumerate(branch)
print('Return Type:',type(obj))
for (i,j) in enumerate(branch):
print('The',i,'element is:',j)
#ord,chr
name='AITS'
n=[]
m=[]
for i in name:
n.append(ord(i))
for j in n:
m.append(chr(j))
print(n,m)
#comparison
l1=[1,2,4,5]
l2=[1,2,5,8]
l3=[1,2,5,8,10]
l4=[1,2,4,5]
print(l2>l1)
print(l2<l3)
print(l1==l4)
'''
OUTPUT
length of mylist is: 4
The first element is: 1
The second element is: 2
The third element is: 3
The fourth element is: 4
mylist[0:3] [1, 2, 3]
mylist[:2] [1, 2]
mylist[1:] [2, 3, 4]
mylist[-3:-1] [2, 3]
mylist[::-1] [4, 3, 2, 1]
After append,the list is: [1, 2, 3, 4, 5]
After insert,the list is: [1, 6, 2, 3, 4, 5]
After append,the list is: [1, 6, 2, 3, 4, 5, [10, 11]]
After extend,the list is: [1, 6, 2, 3, 4, 5, [10, 11], 15, 12, 13, 12]
The sixth element is: [10, 11]
The seventh element is: 15
The eight element is: 12
The sixth of zero index element is: 10
after remove ,the list is: [15, 13, 12]
after delete ,the list is: [15, 13]
before pop() ,the list is: [1, 6, 2, 3, 4, 5, [10, 11], 15, 12, 13, 12]
after pop() ,the list is: [1, 6, 2, 3, 4, 5, [10, 11], 15, 12, 13]
before pop(6) ,the list is: [1, 6, 2, 3, 4, 5, [10, 11], 15, 12, 13]
after pop(6) ,the list is: [1, 6, 2, 3, 4, 5, 15, 12, 13]
before clear() ,the list is: [10, 11]
after clear() ,the list is: []
count(2) is: 3
index(2) is: 1
Sorting is: [1, 2, 3, 4, 5, 6, 12, 13, 15]
Sorting is: [15, 13, 12, 6, 5, 4, 3, 2, 1]
Reverse list is: [1, 2, 3, 4, 5, 6, 12, 13, 15]
[1, 2, 3] [1, 2, 3]
[4, 2, 3] [4, 2, 3]
[4, 2, 3] [4, 2, 3]
[5, 2, 3] [4, 2, 3]
[5, 2, 3] [5, 2, 3]
[6, 2, 3] [5, 2, 3]
Max of mylist is: 15
Min of mylist is: 1
sum of mylist is: 61
all: False
any: True
all: True
any: True
all: False
any: False
Return Type: <class 'enumerate'>
The 0 element is: ece
The 1 element is: eee
The 2 element is: cse
[65, 73, 84, 83] ['A', 'I', 'T', 'S']
True
True
True
'''
#write a python program to demonstrate the woking nested list
grade=[[80,85,90],[75,84,92],[96,75,86]]
exavg=[]
clsavg=[]
for i in range(len(grade)):
print('Student',grade.index(grade[i])+1,'marks:',grade[i])
for k in range(len(grade)):
summ=0
avg=0
for j in range(len(grade[k])):
print('Exam',k+1,'marks:',grade[j][k])
summ+=grade[j][k]
avg=format(float(summ/len(grade)),'.2f')
print('Summation of Exam{}:{}'.format(k+1,summ))
print('Average of Exam{}:{}'.format(k+1,avg))
exavg.append(avg)
print('class average marks of each exam are:',exavg)
m=0
while m<len(grade):
summ=grade[m][0]+grade[m][1]+grade[m][2]
cavg=format(float(summ/len(grade)),'.2f')
clsavg.append(cavg)
m+=1
print('class average marks of each student are:',clsavg)
'''
OUTPUT:
Student 1 marks: [80, 85, 90]
Student 2 marks: [75, 84, 92]
Student 3 marks: [96, 75, 86]
Exam 1 marks: 80
Exam 1 marks: 75
Exam 1 marks: 96
Summation of Exam1:251
Average of Exam1:83.67
Exam 2 marks: 85
Exam 2 marks: 84
Exam 2 marks: 75
Summation of Exam2:244
Average of Exam2:81.33
Exam 3 marks: 90
Exam 3 marks: 92
Exam 3 marks: 86
Summation of Exam3:268
Average of Exam3:89.33
class average marks of each exam are: ['83.67', '81.33', '89.33']
class average marks of each student are: ['85.00', '83.67', '85.67']
'''
#write a python program to demonstrate the working of list comprehension
squares=[x**2 for x in [1,2,3,4]]
print('Squares:',squares)
cubes=[x**3 for x in [1,2,3,4]]
print('cubes:',cubes)
even=[x for x in range(1,11) if x%2==0]
print('Even:',even)
odd=[x for x in range(1,11) if x%2!=0]
print('Odd:',odd)
nums=[-1,1,-2,2,-3,3,-4,4]
new=[x for x in nums if x>0]
print('Positives:',new)
name='welcome to aits'
vow=[v for v in name if v in 'aeiou']
print('Vowels:',vow)
print([ord(ch) for ch in 'AITS'])
mylist=[2,5.2,'ece','aits',.8,4,6,'cse']
print([x for x in mylist if(type(x)==int)])
print([x for x in mylist if(type(x)==float)])
print([x for x in mylist if(type(x)==str)])
#summation of cubes
print([sum([x**3 for x in range(1,21)])])
#temperature
temp=[80,84,85,100,95,101,120,98]
print([t for t in temp if t>=100])
print([format((t-32)*5/9,'.2f') for t in temp if t<100])
#uppercase
print([s.upper() for s in 'aits'])
#vowel comparision
print([x if x in 'aeiou' else '*' for x in 'aits'])
#prime number
print([p for p in range(2,20) if all(p%y!=0 for y in range(2,p))])
#fibonacci
fibo=[0,1]
[fibo.append(fibo[-2]+fibo[-1]) for i in range(0,9)]
print(fibo)
'''
OUTPUT:
Squares: [1, 4, 9, 16]
cubes: [1, 8, 27, 64]
Even: [2, 4, 6, 8, 10]
Odd: [1, 3, 5, 7, 9]
Positives: [1, 2, 3, 4]
Vowels: ['e', 'o', 'e', 'o', 'a', 'i']
[65, 73, 84, 83]
[2, 4, 6]
[5.2, 0.8]
['ece', 'aits', 'cse']
[44100]
[100, 101, 120]
['26.67', '28.89', '29.44', '35.00', '36.67']
['A', 'I', 'T', 'S']
['a', 'i', '*', '*']
[2, 3, 5, 7, 11, 13, 17, 19]
[0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55]
'''
#write a python program to read elements into a list and display them and also find
maximum element in a list
mylist=[]
size=int(input('Enter list size:'))
for x in range(size):
ele=int(input('Enter your element:'))
mylist.append(ele)
print('The list elements are:')
for e in range(len(mylist)):
print(mylist[e],end=' ')
print()
max=min=mylist[0]
sum=0
for e in range(len(mylist)):
if(max<=mylist[e]):
max=mylist[e]
if(min>=mylist[e]):
min=mylist[e]
sum+=mylist[e]
print('The maximum element is:',max)
print('The minimum element is:',min)
print('The summation of all elements is:',sum)
'''
OUTPUT
Enter list size:5
Enter your element:20
Enter your element:10
Enter your element:60
Enter your element:50
Enter your element:40
The list elements are:
20 10 60 50 40
The maximum element is: 60
The minimum element is: 10
The summation of all elements is: 180
'''
#write a python program to demonstrate the working of tuple in pyton
t=(1,2,3)
print(t)
print(t[0])
print(t[-1])
del t
t=()
print(t)
t1=(1)
print(type(t1))
t1=(1,)
print(type(t1))
t2=('ece','eee','cse')
print(t2)
t3=(1,2,3,4,6,5)
print(t3)
t4=t2+t3
print(t4)
print(t4[2:4])
print(t4[: :-1])
print(len(t4))
t5=(t2,t3)
print(t5)
print(t5[0])
print(t5[0][1])
print(any(t3))
print(all(t3))
print(sorted(t3,reverse=True))
print(sum(t3))
print(max(t3))
print(min(t2))
tuple1=tuple('aits')
print(tuple1)
print(tuple1[2])
for x in enumerate(t2):
print(x)
'''
OUTPUT:
(1, 2, 3)
1
3
()
<class 'int'>
<class 'tuple'>
('ece', 'eee', 'cse')
(1, 2, 3, 4, 6, 5)
('ece', 'eee', 'cse', 1, 2, 3, 4, 6, 5)
('cse', 1)
(5, 6, 4, 3, 2, 1, 'cse', 'eee', 'ece')
9
(('ece', 'eee', 'cse'), (1, 2, 3, 4, 6, 5))
('ece', 'eee', 'cse')
eee
True
True
[6, 5, 4, 3, 2, 1]
21
6
cse
('a', 'i', 't', 's')
t
(0, 'ece')
(1, 'eee')
(2, 'cse')
'''
#write a pyton program to encrypt and decrypt the password
pout=' '
casechange=ord('a')-ord('A')
key=(('a','n'),('b','o'),('c','p'),('d','q'),('e','r'),('f','s'),('g','t'),('h','u'),('i','v'),
('j','w'),('k','x'),('l','y'),('m','z'),('n','g'),('o','h'),('p','i'),('q','j'),('r','k'),
('s','l'),('t','m'),('u','a'),('v','b'),('w','c'),('x','d'),('y','e'),('z','f'))
uinput=input('Enter (e) to encrypt and (d) to decrypt:')
while(uinput!='e' and uinput!='d'):
uinput=input('Invalid input!Enter (e) to encrypt and (d) to decrypt:')
encrypt=(uinput=='e')
pin=input('Enter Your password:')
if encrypt:
fromindex=0
toindex=1
else:
fromindex=1
toindex=0
for ch in pin:
lfound=False
for t in key:
if(ch>='a' and ch<='z' and ch==t[fromindex]):
pout+=t[toindex]
lfound=True
elif(ch>='A' and ch<='Z' and chr(ord(ch)+casechange)==t[fromindex]):
pout+=chr(ord(t[toindex])-casechange)
lfound=True
if not lfound:
pout+=ch
if encrypt:
print('Your Encrypted password is:',pout)
else:
print('Your Decrypted password is:',pout)
'''
OUTPUT:
Enter (e) to encrypt and (d) to decrypt:e
Enter Your password:nagendra
Your Encrypted password is: gntrgqkn
Enter (e) to encrypt and (d) to decrypt:d
Enter Your password:gntrgqkn
Your Decrypted password is: nagendra
'''
PROGRAMS ON DICTIONARY & SET TYPE:
#WRITE A PYTHON PROGRAM TO DEMONTARTE THE WORKING OF VARIOUS
OPERATIONS ON DICTIONARY
mydict={
'college':'AITS',
'branch':'ECE',
'count':65
}
print('My Dictionary is:',mydict)
#length
print('Length of dictionary is:',len(mydict))
#accessing
print('First Element:',mydict['college'])
print('Second Element:',mydict['branch'])
print('Third Element:',mydict['count'])
print('First Element using get():',mydict.get('college'))
#adding
mydict['count']=60
mydict['course']='B.Tech'
print('After adding:',mydict)
mydict.update({'branch':'cse','count':63})
print(mydict)
mydict.update({'name':'nag','num':1241})
print(mydict)
mylist=[['a',1],['b',2]]
mydict.update(dict(mylist))
print(mydict)
#removing
del mydict['count']
print(mydict)
val=mydict.pop('course')
print(val,'was deleted.',mydict)
val=mydict.popitem()
print(val,'was deleted.',mydict)
#mydict.clear()
print(mydict)
#setdefault()
x=mydict.setdefault('college','aitsr')
print(x)
print(mydict)
#fromkeys()
x=(1,2,3)
y=('ece','cse','eee')
z=dict.fromkeys(x,y)
print(z)
#keys()
for x in mydict.keys():
print(x)
#values()
for x in mydict.values():
print(x)
#items()
for x in mydict.items():
print(x)
#copy()
new=mydict.copy()
print(new)
'''
OUTPUT:
My Dictionary is: {'college': 'AITS', 'branch': 'ECE', 'count': 65}
Length of dictionary is: 3
First Element: AITS
Second Element: ECE
Third Element: 65
First Element using get(): AITS
After adding: {'college': 'AITS', 'branch': 'ECE', 'count': 60, 'course': 'B.Tech'}
{'college': 'AITS', 'branch': 'cse', 'count': 63, 'course': 'B.Tech'}
{'college': 'AITS', 'branch': 'cse', 'count': 63, 'course': 'B.Tech', 'name': 'nag', 'num': 1241}
{'college': 'AITS', 'branch': 'cse', 'count': 63, 'course': 'B.Tech', 'name': 'nag', 'num': 1241, 'a': 1,
'b': 2}
{'college': 'AITS', 'branch': 'cse', 'course': 'B.Tech', 'name': 'nag', 'num': 1241, 'a': 1, 'b': 2}
B.Tech was deleted. {'college': 'AITS', 'branch': 'cse', 'name': 'nag', 'num': 1241, 'a': 1, 'b': 2}
('b', 2) was deleted. {'college': 'AITS', 'branch': 'cse', 'name': 'nag', 'num': 1241, 'a': 1}
{'college': 'AITS', 'branch': 'cse', 'name': 'nag', 'num': 1241, 'a': 1}
AITS
{'college': 'AITS', 'branch': 'cse', 'name': 'nag', 'num': 1241, 'a': 1}
{1: ('ece', 'cse', 'eee'), 2: ('ece', 'cse', 'eee'), 3: ('ece', 'cse', 'eee')}
college
branch
name
num
a
AITS
cse
nag
1241
1
('college', 'AITS')
('branch', 'cse')
('name', 'nag')
('num', 1241)
('a', 1)
{'college': 'AITS', 'branch': 'cse', 'name': 'nag', 'num': 1241, 'a': 1}
'''
#write a python program to display temperature in a day using dictionary
temp={'sun':68,'mon':73,'tue':75,'wed':82,'thr':86,'fri':94,'sat':97}
daynames={'sun':'sunday','mon':'monday','tue':'tuesday','wed':'wedneday',
'thr':'thursday','fri':'friday','sat':'saturday'}
day=input("Enter 'sun','mon','tue','wed','thr','fri','sat':")
print('The average Temprature of ',daynames[day],'is',temp[day],'degrees')
'''
OUTPUT:
Enter 'sun','mon','tue','wed','thr','fri','sat':wed
The average Temprature of wedneday is 82 degrees
'''
#WRITE A PYTHON PROGRAM TO DEMONTARTE THE WORKING OF VARIOUS
OPERATIONS ON SET
s={}
print(type(s))
s=set()
print(type(s))
s1={1,2,3,4,5,6,4,3,2}
print('myset is:',s1)
#len()
print('My set length is:',len(s1))
#copy()
s3=s1.copy()
print('After copy:',s3)
#add()
s1.add(8)
print('After add:',s1)
#update()
s1.update(['ece','cse'])
print('After Update:',s1)
#remove()
s1.remove(2)
print('After remove:',s1)
#discard()
s1.discard(8)
print('After discard:',s1)
#pop()
print('pop element is:',s1.pop())
print('After pop:',s1)
#clear()
s1.clear()
print('After clear:',s1)
s1.update({1,2,3,'ece','cse',2.5})
print('My New Set:',s1)
s2={1,2,4,5,6,'cse'}
print('set2 is:',s2)
#set operations
#union()
print('After union:',s1|s2)
print('After union:',s1.union(s2))
#insection()
print('After intersection:',s1&s2)
print('After intersection:',s1.intersection(s2))
#difference()
print('After differnece:',s1-s2)
print('After difference:',s1.difference(s2))
print('After differnece:',s2-s1)
print('After difference:',s2.difference(s1))
#symmetric_differnce()
print('After symmetric_differnece:',s1^s2)
print('After symmetric_difference:',s1.symmetric_difference(s2))
#insection_update()
s1.intersection_update(s2)
print('After intersection_update:',s1)
#difference_update()
s2.difference_update(s1)
print('After difference_update:',s2)
#symmetric_difference_update()
s1.symmetric_difference_update(s2)
print('After symmetric_difference_update:',s1)
#isdisjoint()
print(s1.isdisjoint(s2))
#issubset()
print(s2.issubset(s1))
#issuperset()
print(s1.issuperset(s2))
'''
OUTPUT:
<class 'dict'>
<class 'set'>
myset is: {1, 2, 3, 4, 5, 6}
My set length is: 6
After copy: {1, 2, 3, 4, 5, 6}
After add: {1, 2, 3, 4, 5, 6, 8}
After Update: {1, 2, 3, 4, 5, 6, 'cse', 8, 'ece'}
After remove: {1, 3, 4, 5, 6, 'cse', 8, 'ece'}
After discard: {1, 3, 4, 5, 6, 'cse', 'ece'}
pop element is: 1
After pop: {3, 4, 5, 6, 'cse', 'ece'}
After clear: set()
My New Set: {1, 2, 3, 2.5, 'ece', 'cse'}
set2 is: {1, 2, 4, 5, 6, 'cse'}
After union: {1, 2, 3, 2.5, 4, 'cse', 5, 6, 'ece'}
After union: {1, 2, 3, 2.5, 4, 'cse', 5, 6, 'ece'}
After intersection: {1, 2, 'cse'}
After intersection: {1, 2, 'cse'}
After differnece: {'ece', 2.5, 3}
After difference: {'ece', 2.5, 3}
After differnece: {4, 5, 6}
After difference: {4, 5, 6}
After symmetric_differnece: {'ece', 2.5, 3, 4, 5, 6}
After symmetric_difference: {'ece', 2.5, 3, 4, 5, 6}
After intersection_update: {1, 2, 'cse'}
After difference_update: {4, 5, 6}
After symmetric_difference_update: {1, 2, 4, 5, 'cse', 6}
False
True
True
'''
PROGRAMS ON FUNCTIONS:
#WRITE A PYTHON PROGRAM TO PERFORM ADDITION BETWEEN TWO NUMBERS
USIN FUNCTION
def add(a,b):
"""this function display addition of two numbers"""
return(a+b)
a=int(input('Enter a value:'))
b=int(input('Enter b value:'))
result=add(a,b)
print('The addition of %d and %d is %d'%(a,b,result))
'''
OUTPUT:
Enter a value:10
Enter b value:20
The addition of 10 and 20 is 30
'''
#write a python program to find average of three numbers using function
def avg(n1,n2,n3):
return (n1+n2+n3)/3.0
print(avg(10,20,30))
print(avg(10,20,30)+10)
if avg(10,23,-40)<0:
print('invalid')
print(avg(avg(1,2,3),5,7))
print(avg(1,2,3)*avg(1,2,3))
'''
20.0
30.0
invalid
4.666666666666667
4.0
'''
#WRITE A PYTHON PROGRAM TO DEMONSTRATE THE WORKING OF DIFFERENT
ARGUMENTS IN PYTHON FUNCTIONS
def message1(fname,lname):
print(fname+" "+lname)
def message2(first,last):
print(first+" "+last)
def message3(first,last,age=30): #default parameter
print(first+" "+last)
print('age=',age)
def message4(*name): #Arbitrary argument
print(name)
print(name[0]+" "+name[1])
def message5(**name): #Arbitrary keyword argument
print(name)
print(name['first']+" "+name['last'])
return name
fname=input('Enter First name:')
lname=input('Enter last name:')
message1(fname,lname)#positional arguments
fname1=input('Enter First name:')
lname2=input('Enter last name:')
message2(first=fname1,last=lname2)#keyword arguments
message3(last=lname2,first=fname1)
message4('naga','endra')
result=message5(first='ece',last='cse')
print(result)
'''
OUTPUT:
Enter First name:PIDUGU
Enter last name:NAGENDRA
PIDUGU NAGENDRA
Enter First name:PIDUGU
Enter last name:NAGENDRA
PIDUGU NAGENDRA
PIDUGU NAGENDRA
age= 30
('naga', 'endra')
naga endra
{'first': 'ece', 'last': 'cse'}
ece cse
{'first': 'ece', 'last': 'cse'}
'''
#write a python program to demonstrate the working of mutable arguments in
python functions
def findsum(num):
for x in range(len(num)):
if num[x]<0:
num[x]=0
return sum(num)
mylist=[]
size=int(input('Enter size of list:'))
for k in range(size):
mylist.append(int(input('Enter value:')))
print('My list is:',mylist)
result=findsum(mylist)
print('My list is:',mylist)
print('Result is:',result)
'''
OUTPUT:
Enter size of list:5
Enter value:-1
Enter value:2
Enter value:3
Enter value:-7
Enter value:5
My list is: [-1, 2, 3, -7, 5]
My list is: [0, 2, 3, 0, 5]
Result is: 10
'''
#WRITE A PYTHON PROGRAM TO DEMONSTARTE THE WORKING OF KEYWORD
AND DEFAULT ARGUMENT
def addup(first,last,incr=1):
if(first>last):
sum=-1
else:
sum=0
for x in range(first,last+1,incr):
sum+=x
return sum
print(addup(1,10))
print(addup(1,10,2))
print(addup(first=1,last=10))
print(addup(first=1,last=10,incr=2))
'''
OUTPUT:
55
25
55
25
'''