Please write this program .. Ask the user to enter a list containing no's between 1&12 . Then replace all of the entries in the list that are greater then 10 with 10 | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Please write this program .. Ask the user to enter a list containing no's between 1&12 . Then replace all of the entries in the list that are greater then 10 with 10

10th Jan 2017, 3:37 AM
Prabhakar Banafar
Prabhakar Banafar - avatar
9 Answers
+ 8
Well, this is quite late, but in such an application, I suggest doing such modifications to the numbers before adding them to the list, to avoid the following iteration of the list.
29th Jan 2017, 12:27 AM
Dao
Dao - avatar
+ 5
liste=[] for i in range(5): num=int(input("Enter a number: ")) liste.append(num) for i in liste: if i>10: liste[liste.index(i)]=10 print(liste) this is for a list with 5 numbers, but feel free to make that number higher if you want to
10th Jan 2017, 12:49 PM
ramzi
ramzi - avatar
+ 3
Just started learning Python this week, but I still tried. a = int(input('number1\n')) b = int(input('number2\n')) c = int(input('number3\n')) d = int(input('number4\n')) e = int(input('number5\n')) f = int(input('number6\n')) g = int(input('number7\n')) h = int(input('number8\n')) i = int(input('number9\n')) j = int(input('number10\n')) k = int(input('number11\n')) l = int(input('number12\n')) z = (a,b,c,d,e,f,g,h,i,j,k,l) if 10 in z: print ('10') if 11 in z: print ('10') if 12 in z: print ('10') else: print ('Error, please enter numbers from 1 to 12 only!')
10th Jan 2017, 5:24 AM
Varun Anand
+ 2
Couldn't you remove the print line and pass the string as an argument to the input method? Another small thing is that he didn't request for printing.
10th Jan 2017, 4:45 AM
Dao
Dao - avatar
+ 1
How big should the list be?
10th Jan 2017, 4:10 AM
Dao
Dao - avatar
+ 1
The print was to demonstrate that you have to convert return value of map from iterable to list to print it. It would be fine to print iterables as well.
10th Jan 2017, 5:11 AM
Arjav Dave
Arjav Dave - avatar
0
def replace(x): if x > 10: return 10 return x len = int(input("Enter the number of elements in list")) i = 0 l = [] while i < len: l.append(float(input())) i+=1 print(list(map(replace,l)))
10th Jan 2017, 4:38 AM
Arjav Dave
Arjav Dave - avatar
0
What can you do with a list of "no's"?
28th Jan 2017, 2:54 PM
Michael Timbes
Michael Timbes - avatar
0
no's = numbers. @Michael Timbes
28th Jan 2017, 5:35 PM
ramzi
ramzi - avatar