lundi 24 octobre 2022

How to randomly generate numbers each time the program is run and store those values in a list?

I am writing a program that asks the user to input a list of students. Once the list is made the user can input a student's name that was listed before to show 4 random integers from 1 to 100 that represent 4 different marks on assignments. When I run this program, however, the mark is the same number each time. How do I run the program so that each number for the mark is different, also how can I store these values in a separate list? Thank You!

def printMark(studentMark, studentName):
    print("Enter the names of your students")
    print("Press the enter key to store another name. print q or Q when you're done.")
    names = input("Enter student name: \n")
    classlist = []

    while True:
        names = input("")
        if str.lower(names) == 'q':
            break
        classlist.append(names)

    for name in classlist:
        print(name)

    student_choice = input("Enter a students in your classlist: ")
    if student_choice not in classlist:
        print("That students is not in your class")
    elif student_choice in classlist:
        mark = list(range(1, 101))
        print("A1:" + str(studentMark) + "\nA2:" + str(studentMark) + "\nA3:" + str(studentMark) + "\nA4:" + str(studentMark))

classlist = []
import random
mark = list(range(1, 101))
printMark(random.sample(mark, k=4), classlist)



Aucun commentaire:

Enregistrer un commentaire