Page 378 - Computer Science Class 11 Without Functions
P. 378
Program 14
Write a program that takes a list as an input and prints the largest and smallest numbers from the list.
Ans. '''
Objective: To find the largest and smallest number in the list
Input: myList
Output: largest and smallest number
'''
myList = []
num = int(input("Enter the number of elements that you want of add to the
list : "))
for x in range(num):
item = int(input("Enter number : "))
myList.append(item)
print("The list formed is : ", myList)
print("The largest number is ", max(myList))
print("The smallest number is ", min(myList))
Program 15
Write a program that takes a user-provided list as input and then generates a new list comprising swapped values at
odd indices with those at even indices.
Ans. '''
Objective: To swap values at odd indices with those at even indices
Input: myList - list
Output: list with swapped values
'''
myList = []
num = int(input("Enter the number of elements that you want of add to the
list : "))
for x in range(num):
item = int(input("Enter number : "))
myList.append(item)
print("The list formed is : ", myList)
for x in range(0,len(myList)-1,2):
myList[x], myList[x+1] = myList[x+1],myList[x]
print("The list after swapping odd indices with those at even indices is: ",
myList)
376 Touchpad Computer Science-XI

