Hi, I'm new to Python - and new on here....

I've read lots of tutorials on Python and am currently in an intro to programming class using python, but I can't figure this out. I've searched stack overflow, dani web, java2s, github and many others but can't understand what I'm doing wrong.

This is for a final project in my programming class and I'd like to do a couple of things in class and then import them into the main program.

Eventually I hope to use this in my workplace as well and I want it to present the user with a menu of options. 1: Add names and typing speeds. 2: delete a name by value(the name of a student -- I'd like to do this with a class if possible. 3: print the names and speeds. 4: print a list of the speeds. 5: print the average speeds from the list of speeds (which I'd also like to do in a class). and 6 to quit the program.

I tried to be ambitious and create a random name generator so I created a function to print the list of names as well, but this is due Monday morning so I scrapped that project since I wasn't getting anywhere.

The parts that aren't working are #2 - deleting a name and #3 - averaging the score. On #2, I haven't had any luck trying .remove, del, or any other things I've seen people try. It seems most of examples are only hard coded in. The others don't make sense to me. On #3, I've tried multiple calculations including adding the numbers together separately, creating different functions and dividing by len and I've tried the mean built_in.

I can turn the assignment in based on what is working, but the other pieces would be especially helpful for when it is used for a purpose.

FYI I am using Python 3 and my class file is saved as studentClass.

Here is my class program:

class student_info:

    def __init__(self):
        self.name = ""
        self.speed = ""
        self.speed_average = 0

    def speed_average(self):
        return sum(self.speed) / len(self.speed)

and the main program (with comments):

import studentClass

name_list = []
speed = 0

def edit_list(name):
    new_name = input("What is the student's name? ")
    if new_name != "":
        name.name = new_name

    while True:
        try:
            typing_speed = input("What was the last typing speed? ")
            if speed != "":
                name.speed = float(typing_speed)
                #print (test_score)
            else:
                raise ValueError
            break
        except ValueError:
            print("Not a valid score.")

def print_students(list):
    for i, n in enumerate(list):
        print("#%d: Name: %s, Typing Speed (wpm): %d" % (i+1, n.name, n.speed))

def print_speed(list):
    for i, n in enumerate(list):
        print("%s" % (n.speed))

##Since the class instantiation didn't work, I tried creating a function - that didn't work either.
def print_avg(list):
    speed_list = speed
    print(sum(speed)/len(speed))

while True:
    print("Hi user, (1) add (2) delete (3) print (4) print scores (5) print average (6) quit")
    choice = input(" >> ")
    if choice == '1':
        name_list.append(studentClass.student_info())
        edit_list(name_list[-1])
    elif choice == '2':
        names = [name_list]       
        del_name = input("What name would you like to remove? ")
        name_list.remove(del_name)
        if del_name not in name_list:
            print("Name not found.")
        else:
            print("%s removed." % del_name)
    elif choice == '3':
        print_students(name_list)           
    elif choice == '4':
        print_speed(name_list)
    elif choice == '5':
        class_avg = studentClass.student_info()
        print("Average score for class: " %(class_avg.speed_average()))
    elif choice == '6':
        print('Happy Typing!')
        break
    else:
        print("That's not an option. Please try again.")







Error returned when #2 is selected:
Hi user, (1) add (2) delete (3) print (4) print scores (5) print average (6) quit
 >> 1
What is the student's name? john
What was the last typing speed? 20
Hi user, (1) add (2) delete (3) print (4) print scores (5) print average (6) quit
 >> 1
What is the student's name? mary
What was the last typing speed? 10
Hi user, (1) add (2) delete (3) print (4) print scores (5) print average (6) quit
 >> 4
20.0
10.0
Hi user, (1) add (2) delete (3) print (4) print scores (5) print average (6) quit
 >> 3
#1: Name: john, Typing Speed (wpm): 20
#2: Name: mary, Typing Speed (wpm): 10
Hi user, (1) add (2) delete (3) print (4) print scores (5) print average (6) quit
 >> 2
What name would you like to remove? john
Traceback (most recent call last):
  File "C:\Users\Whited\Desktop\Classes\Programming\studentRun.py", line 44, in <module>
    name_list.remove(del_name)
ValueError: list.remove(x): x not in list
>>>



Error returned when #5 is selected:



>>> ================================ RESTART ================================
>>> 
Hi user, (1) add (2) delete (3) print (4) print scores (5) print average (6) quit
 >> 1
What is the student's name? john
What was the last typing speed? 20
Hi user, (1) add (2) delete (3) print (4) print scores (5) print average (6) quit
 >> 1
What is the student's name? mary
What was the last typing speed? 10
Hi user, (1) add (2) delete (3) print (4) print scores (5) print average (6) quit
 >> 5
Traceback (most recent call last):
  File "C:\Users\Whited\Desktop\Classes\Programming\studentRun.py", line 56, in <module>
    print("Average score for class: " %(class_avg.speed_average()))
TypeError: 'int' object is not callable
>>> 

Got some responses on Stack Overflow and got a really valuable response with explanation ~ Thanks all!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.