0% found this document useful (0 votes)
2 views5 pages

All Program

The document contains a series of Python programming exercises that demonstrate various concepts such as functions, user input, conditional statements, loops, and list operations. Each section includes code snippets that illustrate how to implement these concepts, including calculating areas, checking eligibility for voting, and creating dynamic lists. The exercises are aimed at helping learners practice and understand fundamental programming skills in Python.

Uploaded by

j80369949
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views5 pages

All Program

The document contains a series of Python programming exercises that demonstrate various concepts such as functions, user input, conditional statements, loops, and list operations. Each section includes code snippets that illustrate how to implement these concepts, including calculating areas, checking eligibility for voting, and creating dynamic lists. The exercises are aimed at helping learners practice and understand fundamental programming skills in Python.

Uploaded by

j80369949
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

==================================================================

1. Write A Function to Print Message And Your Name :-


==================================================================

name=str(input('Enter Your Name :- '))


def welcome():
print('Welcome '+name+' in First Python Program')

welcome() # function call

==================================================================
2. Write to print area of rectangle :- [UDF]
==================================================================

l=int(input('Enter The Length :- '))


b=int(input('Enter The Breadth :- '))
def areaOFRect(l,b):
return l*b
ans=areaOFRect(l,b)
print(ans)

==================================================================
3. Function with Default Parameter :- [UDF]
==================================================================

def fun(country='India'):
print('I Am From ',country)
fun('London')
fun()
fun('Ukrain')

==================================================================
4. To print charact with positive or negative index :-
==================================================================
# positive index count

name='Hello there i am using python'


print(name[3])
print(name[4:])
print(name[:10])
print(name[2:26]) # last 26th index was not counted

# Negative index count

name='Hello there i am using python'


print(name[-3])
print(name[-4:])
print(name[:-10])
print(name[-20:-6]) # last -6th index was not counted

==================================================================
5. to check eligibility for voting by take user input:-
==================================================================

age=int(input('Enter your age :- '))


if age >= 18:
print('Your age is ',age,' so you are eligible for voting.')
else:
print('Your age is ',age,' so you are not eligible for voting.')
==================================================================
6. To chech whether number is positive or negative :-
==================================================================

a=int(input('Enter any value :- '))


if a > 0:
print('Your number ',a,' is positive')
elif a < 0:
print('Your number ',a,' is negative')
else:
print('Your number is 0')

==================================================================
7. to check number is between 40 and 50 (Nested if...else...) :-
==================================================================

a=int(input('Enter any number :- '))


if a < 50:
if a > 40:
print('Your number is between 40 and 50')
else:
print('Your number is not between 40 and 50')
else:
print('Your number is not between 40 and 50')

==================================================================
8. Print n numbers and sum of it (while loop):-
==================================================================

i=1;
sum=0
a=int(input('Enter any number :- '))
while i <= a:
print(i)
sum=sum+i
i+=1
print('Sum = ',sum)

==================================================================
9. Print sum of odd number and even :-
==================================================================

i=0
sum=0
a=int(input('Enter any value :- '))
while i <= a:
if i % 2 == 0:
print(i)
sum+=i
i+=1
print('Sum = ',sum)

j=0
sum=0
b=int(input('Enter any value :- '))
while j <= b:
if j % 2 == 1:
print(j)
sum+=j
j+=1
print('Sum = ',sum)

==================================================================
10. nested while loop [pattern 1] :-
==================================================================

'''
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
'''

i=1
while i<=5:
j=1
while j<=i:
print(j, end=' ')
j+=1
print()
i+=1

==================================================================
11. nested while loop :-
==================================================================

'''
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
'''
i=1
while i<=5:
j=1
while j<=i:
print(i, end=' ')
j+=1
print()
i+=1

==================================================================
12. Nested loop :-
==================================================================

'''
*
# #
* * *
# # # #
* * * * *
'''
i=1
while i<=5:
j=1
while j<=i:
if i%2==0:
print('#', end=' ')
else:
print('*', end=' ')
j+=1
print()
i+=1

==================================================================
13. Nested loop :-
==================================================================

'''
1
2 3
4 5 6
7 8 9 10
'''
i=1
k=1
while i<=4:
j=1
while j<=i:
print(k, end=' ')
k+=1
j+=1
print()
i+=1

==================================================================
14. make a list of strings and print positive & negative index :-
==================================================================

list=['Orange','Cherry','Grapes','Apple','Banan','Guava','Blue berry','Custard
apple']
print(list[3])
print(list[3:])
print(list[:6])
print(list[3:6]) # 6th index is not count

print(list[-3])
print(list[-6:])
print(list[:-2])
print(list[-6:-3]) # -3rd index is not count

==================================================================
15. list 10 elements of fruits :-
'''
1. add kiwi fruit at the end ?
2. count watermelon in list ?
3. add papaya at 3rd index ?
4. remove element present at 5th position ?
5. remove banana from list ?
'''
==================================================================

list=['Apple','Watermelon','Banana','Cherry','Guava','Orange','Grapes','Lichi','Cus
tard apple','Mango']
[Link]('Kiwi')
print(list)

print([Link]('Watermelon'))

[Link](3,'Papaya')
print(list)

[Link](5)
print(list)

[Link]('Banana')
print(list)

==================================================================
16. Create dynamic list and calculate sum of it :-
==================================================================

i=0
sum=0
a=int(input('Enter element size :- '))
list=[]
while i<a:
no=int(input('Enter numbers :- '))
[Link](no)
sum+=list[i]
i+=1
print(list)
print('sum = ',sum)

==================================================================
17. Create dynamic list and calcualte sum & Count it :-
==================================================================

i=0
sum=0
list=[]
a=int(input('Enter size :- '))
while i<a:
no=int(input('Enter No :- '))
[Link](no)
sum+=list[i]
i+=1
print(list)
print('Sum = ',sum)
print([Link](5))

You might also like