Python Forum
Collecting Average User Statistics? 1st semester programmer
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Collecting Average User Statistics? 1st semester programmer
#4
For documentation and maybe to help other people, here's my functioning code.

# This program will help my fellow students to determine how
# many hours they need to study to get good grades.
# Study and Grade Calculator Version 1.00 updated Feb 12, 2020

# Initialize variables
runAgain = 'Y'
totalStudents = 0

averageCredits = 0
averageStudy = 0 
totalCredits = 0
totalStudy = 0


##### Welcome user to the Study and Grade Calculator program.
print("Welcome to the Study and Grade Calculator\n" +
      "By Andrew Rodriguez \n" +
      "Version 1.00 updated Feb 12, 2020\n\n")

# Loop continues as long as user enter Y or y
while runAgain == 'Y' or runAgain == 'y' or runAgain == 'yes' or runAgain == 'Yes': 
    


##### Collect user data: Name, Credits, and Grade desired.
# Ask user's name and validate data
    userName = input('Please enter your full name (First, Last): \n')
    while userName == "" or userName.isdigit():
        print('Invalid name')
        userName = input('Please enter your full name (First, Last): \n')

    totalStudents = 1 + totalStudents

# creditAmount.isdigit()
# Ask user for number of credits they are taking and validate data
    creditAmount = int(input("Please enter how many credits you're taking: \n")) 
    while (creditAmount) < 0 or (creditAmount) >= 20:
        print('Invalid amount of credits')
        creditAmount = int(input('Please enter how many credits you are taking: \n'))
        
    totalCredits = creditAmount + totalCredits
    
# Ask user to enter the grade they want and validate data
    desiredGrade = input('Please enter your desired letter grade: \n')
    while desiredGrade == "" or desiredGrade.isdigit():
        print('Invalid grade')
        desiredGrade = input('Please enter a valid desired letter grade: \n')


# Desired grade decision structure
    if desiredGrade == "A" or desiredGrade == "a":
        studyHours = 15
    elif desiredGrade == "B" or desiredGrade == "b":
        studyHours = 12
    elif desiredGrade == "C" or desiredGrade == "c":
        studyHours = 9
    elif desiredGrade == "D" or desiredGrade == "d":
        studyHours = 6
    elif desiredGrade == "F" or desiredGrade == "f":
        studyHours = 0
    else:
        print('Invalid Grade')
        studyHours = 'Invalid Grade'
        
    totalStudy = totalStudy + studyHours

# Average user statistics calculator

    averageStudy = totalStudy / totalStudents
    averageCredits = totalCredits / totalStudents
    
    
##### Display results
    print("\nName: ", userName, "\nCredits: ", creditAmount, "\nStudy Hours: ", studyHours,
          "\nGrade: ", desiredGrade)

    print()
    print(-User Stats-)
    print("\nTotal Students: ", totalStudents, "\nAverage Study Hours: ",
          averageStudy, "\nAverage Credit Hours: ", averageCredits)
   
    
# Ask the user if they want to run this program again
    runAgain = input('Would you like to run this program again? (Y/N)')
          
# Thank the user for using the application
print('Thank you for caring about your grades!')
Reply


Messages In This Thread
RE: Collecting Average User Statistics? 1st semester programmer - by Jagsrs28 - Mar-05-2020, 08:05 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Rock, Paper, Scissors Advanced that saves, loads, and keeps statistics EvanCahill 0 5,231 Jul-21-2018, 07:32 PM
Last Post: EvanCahill
  Statistics from text file Zatoichi 1 4,245 Feb-05-2018, 04:52 AM
Last Post: ka06059

Forum Jump:

User Panel Messages

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