0

# Python: problem with mediana in random number's list

Hi, I don't know what I did wrong. It's probably very simple, but I just can't find the answer, how sort the list and print mediana? I'd appreciate your help. #random numbers 0-20 import random for i in range(20): nums=random.randint(0,20) print(nums) #sort the list nums print (sorted(str(nums))) #mediana ?

5 Answers

0

Something like this:
print(sorted(nums)[len(nums)//2])

0

Unfortunately, it doesn't work. "TypeError: 'int' object is not iterable." Don't understand why.
But thanks anyway.

0

I think it should work. Works on my computer:
>>> a = [1,3,4, 2,5]
>>> print(sorted(a)[len(a)//2]
3

0

Of course, it works with a normal list, but not with my random number's list, or maybe I did something wrong in the first part? The problem is function sorted doesn't work in this code too :/

0

nums = []
for i in range(20)
nums.append(random.randint(0,20)