Professional Documents
Culture Documents
Python Program Assignment
Python Program Assignment
Student id:94929
(Answer)
for i in range(len(l)):
if (i<len(l)):
print(“enter”,len(l)-I,”more numbers.”)
elif(i>len(l))
print(“You have reached the limit of the needed numbers.”)
Output:
List:1,2,3,4,5,6,7,8,9,12,32,21,46,33,43,55,66,77,76,43
The list is ['1', '2', '3', '4', '5', '6', '7', '8', '9', '12', '32', '21', '46', '33', '43', '55', '66', '77', '76', '43']
The smallest element in the list is 1
Screenshot:
def myMax(list1):
# Driver code
list1 = [1,2,0,3,4,5,6,7,8,9,11,22,33,44,55,66,77,88,99,122]
print(list1)
print("Largest element is:", myMax(list1))
Output:
>>>
= RESTART: C:/Users/Jayanth Jaidev/AppData/Local/Programs/Python/Python38-32/greatest.py
[1, 2, 0, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33, 44, 55, 66, 77, 88, 99, 122]
Largest element is: 122
Screenshot:
(iii) Python program to find the sum of the numbers in the list:
numbers = [1,2,3,4,5,6,7,8,9,0,11,22,33,44,55,66,77,88,99,145]
Output:
Sum of the numbers in the list is: 685
Screenshot:
numbers = [1,2,3,4,5,6,7,8,9,0,11,22,33,44,55,66,77,88,99,145]
Output:
Sum of the numbers in the list is 685
Average is 34.25
Screenshot:
2- In a program, write a function that accepts two arguments: a list
and a number n. Assume that the list contains numbers. The
function should display all the numbers in the list that are greater
than the number n.
def main():
#declares local variables
n = 14
number_list = [1,2,3,6,5,8,11,7,12,16,18,23,45,65,87,77]
print('Number:', n)
#Display the list of numbers that are larger than the given number
display_larger_than_n_list(number, number_list)
larger_than_n_list = []
larger_than_n_list.append(value)
print(larger_than_n_list)
main()
Output:
Number: 14
List of numbers:
[1, 2, 3, 6, 5, 8, 11, 7, 12, 16, 18, 23, 45, 65, 87, 77]
List of numbers that are larger than 14:
[16, 18, 23, 45, 65, 87, 77]
Screenshot:
3- Write a turtle graphics program to display 20 circles centered at
location 0, 0 (all of them). Increase the radius of each
consecutive circle by 20. First circle should have radius 20,
second radius 40, and so on.
import turtle
turtle.penup()
for i in range(1, 400, 20):
turtle.right(90)
# Pen up
turtle.penup()
Screenshot: