-
Notifications
You must be signed in to change notification settings - Fork 0
/
task_7.py
52 lines (43 loc) · 1.36 KB
/
task_7.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# -*- coding: utf-8 -*-
"""TASK 7.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1xIBYyQwENSR8Qb-a0sGw1DeRfveGVsjd
1. Write a program to check whether a string is palindrome or not using functions.
( A function is to be created to check whether the string is palindrome and it should give the output true or false to the main program)
"""
def palindrome(str):
if str[::-1]==str:
print("entered string is palindrome")
else:
print("entered string is not palindrome")
str= input("enter a string :")
palindrome(str)
"""2. Write a menu driven program to find largest element in L, smallest element, avg of all values, sum of all values in L. All these operation should be performed in different functions and the result should be returned.
L=[23,24,11,90,1,41,9,99,28,56,72]
"""
L=[23,24,11,90,1,41,9,99,28,56,72]
def large(L):
max = L[0]
for x in L:
if x > max :
max = x
return max
print("Largest element is:", large(L))
def small(L):
min = L[0]
for x in L:
if x < min :
min = x
return min
print("small element is:", small(L))
def sum(L):
s=0
for y in L:
s=s+y
return s
print("sum of elements in list:",sum(L))
def avg(L):
avg=sum(L)/len(L)
return avg
print("average of elements in list is:",round(avg(L),3))