Selecting random student code

IB Year 1 HL Computer Science
Forum rules
Please be careful about sharing personal information. Never use any identifiable information.
Post Reply
User avatar
minseok123
Helper!
Posts: 9
Joined: 17 Sep 2018, 10:14

Selecting random student code

Post by minseok123 » 16 Oct 2018, 22:19

Code: Select all

import random
import os

students_in_classes = [
    ["Jake", "Kim", "Lee"],
    ["Pol", "Laa","Deng"],
    ["Sam", "Pen", "Wom"],
    ["Ree", "Asen", "Rom"],
    ["Kim", "Alex", "Kris"]
    ]


def random_student ():
    print(random.choice(new_class))


def clear_screen():
    os.system("cls" if os.name == "nt" else "clear")


def show_classes ():
    index = 1
    for classes in students_in_classes:
        print("{}.".format(index), classes)
        index += 1


show_classes()

class_number = input("What is the number of the class of which you're teaching? ")
clear_screen()
new_class = students_in_classes[int(class_number) - 1]

print("Your class:")
print(new_class)


x = input("Press ENTER to randomly select a student")
if x == x:
    random_student()
How do I make it so that I can new_class -= the value returned when the function random_student is called?
1 x

User avatar
Mr. MacKenty
Site Admin
Posts: 88
Joined: 28 Apr 2018, 17:06
Answers: 3

Re: Selecting random student code

Post by Mr. MacKenty » 17 Oct 2018, 16:00

I am confused.

What exactly are you trying to do here? Why do you need to decrement:

Code: Select all

new_class = students_in_classes[int(class_number) - 1]
0 x

Post Reply