+ 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
9 Antworten
+ 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.
+ 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
+ 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!')
+ 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.
+ 1
How big should the list be?
+ 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.
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)))
0
What can you do with a list of "no's"?
0
no's = numbers. @Michael Timbes