Computer Science
Ask the user to enter a list containing numbers between 1 and 12. Then replace all of the entries in the list that are greater than 10 with 10.
Answer
l = eval(input("Enter list having numbers between 1 & 12: "))
for i in range(len(l)):
if l[i] > 10:
l[i] = 10
print("List after removing numbers greater than 10:")
print(l)
Output
Enter list having numbers between 1 & 12: [1, 3, 15, 8, 20]
List after removing numbers greater than 10:
[1, 3, 10, 8, 10]
Related Questions
Write a program that reverses a list of integers (in place).
Write a program that inputs two lists and creates a third, that contains all elements of the first followed by all elements of the second.
Ask the user to enter a list of strings. Create a new list that consists of those strings with their first characters removed.
Write a program to check if a number is present in the list or not. If the number is present, print the position of the number. Print an appropriate message if the number is not present in the list.