maisui童鞋 maisui童鞋 - 1 year ago 73
Python Question

how to make a random list in python3

i just want make a list to display students scores and different course have different scores ,the scores comes from.random randint(70,100), like this:


import random
def makedict(spam):
for j in range(20):
for i in spam:
return a
if __name__=="__main__":

IndexError: list index out of range
how i change the code

Answer Source

Try this, You have to use append.

import random
def makedict(spam):
    result = []
    for _ in range(20):
        result.append({j:random.randint(70,90) for j in spam})
    return result

if __name__=="__main__":
    cou=['C++','Math', 'Python']
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download