Python Forum
Creating Program Homework
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Creating Program Homework
#1
Create a python program that gets students lastname, firstname, and finalmark, then calculates the letter grade based on the following criteria;

A student with mark lower than 50 should receive a letter grade F, between 50 and 54 receives D, between 55 and 64 a C, 65 and 79 should receive a B and anything equal and above 80 should be an A.

Your program should utilize the following functions

a) getLastname(), returns student first name
b) getFirstname(), returns student first name
c) getMark(), returns student mark
d) computeGrade(), which accepts student mark and returns appropriate letter grade
e) student(), that gets relevant student data (lastname, first name, mark, and letter grade) and stores it as a single object (list)
f) classlist() that repeatedly asks if there are more students and stores multiple students data as single object, list
g) displayClasslist() that displays the classlist as shown by the following example;



Any more student in your class? (yes/no) yes

Student's Last name: Larson

Student's first name: Carson

Enter the student's mark: 90

Any more student in your class? (yes/no) yes

Student's Last name: Johnson

Student's first name: Bob

Enter the student's mark: 80

Any more student in your class? (yes/no) no

Computer's 101 Classlist

LastName FirstName Mark. Final Grade

------------------------------------------------------------------

Larson Carson 90 A

Johnson Bob 80 A

Your program should only accept valid names (only alphabets characters) and mark (between 0 and 100).


This is what I have so far:

 def classlist():
    more_students = input("Any more students in your class? (yes/no) ")
    
def getLastname():
    last_name = input("\nStudent's last name: ")
    print()
    
    return last_name

def getFirstname():
    first_name = input("Student's first name: ")
    print()
    
    return first_name
    
def getMark():
    student_mark = input("Enter the student's mark: ")
    print()
    
    return student_mark

def computeGrade():
    score = int(round(score))
    if score >= 80: return "A"
    if score >= 65 and score <= 79: return "B"
    if score >= 55 and score <= 64: return "C"
    if score >= 50 and score <= 54: return "D"
    if score < 50: return "F"




def program():
    more_students = classlist()
    last_name = getLastname()
    first_name = getFirstname()
    student_mark = getMark()
    score = computeGrade()
    
program() 
Kinda stuck at this point as to what I'm supposed to do next. Help?!
Reply
#2
learning while helping others... please post differences/corrections made by your teacher if any, will help me as well
def getLastname():
    last_name = input("\nStudent's last name: ")  
    return last_name
 
def getFirstname():
    first_name = input("Student's first name: ") 
    return first_name
     
def getMark():
    student_mark = input("Enter the student's mark: ")
    return student_mark
 
def computeGrade(student_mark):
    score = round(float(student_mark))
    if score >= 80: return "A"
    elif score >= 65 and score <= 79: return "B"
    elif score >= 55 and score <= 64: return "C"
    elif score >= 50 and score <= 54: return "D"
    elif score < 50: return "F"
 
def student(last_name,first_name,student_mark,score):
    return [last_name,first_name,student_mark,score]
    
def displayClasslist(classlist):
    print 'Computer\'s 101 Classlist'
    print '-------------------------'
    
    for lastname,firstname,mark,grade in classlist:
        print lastname,firstname,mark,grade
    
def classlist():
    studentlist = []
    while True:
        more_students = input("Any more students in your class? (yes/no) ")
        if more_students != 'yes':
            break
        last_name = getLastname()
        first_name = getFirstname()
        student_mark = getMark()
        score = computeGrade(student_mark)
        studentlist += [student(last_name,first_name,student_mark,score)]
    return studentlist
    
displayClasslist(classlist())
swallow osama bin laden
Reply
#3
Since the name should be alphabetical and the mark between 0 and 100 it's better to check for these conditions in the get_* functions in a while loop.

# pseudo code
while True:
    name = input()
    if name is alphabetical:
        return the name

Similar to the get_mark function
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  homework hospital charges program help ccm1776 5 4,784 Oct-21-2018, 03:22 AM
Last Post: Skaperen
  Help on Creating Program to find the Median and Mode by hand EvanCahill 3 2,997 Jul-19-2018, 06:17 PM
Last Post: woooee

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020