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
#2
(Mar-05-2020, 01:54 AM)Jagsrs28 Wrote: Getting the average credits and average study hours, I assume I would use a for loop.
I didn't understand: why do you need to use a for-loop. You have the number of students and total value of credits. Mean value is a fraction of the total amount of credits and the number of students, isn't it?

I would also suggest some refactorings, e.g.
# define a dict

grade_mapper = {'a': 15,
                'b': 12,
                'c': 9,
                etc... }
# you can rewrite if/elif-series as follows:

study_hours = grade_mapper.get(desiredGrade.lower(), None)  # I leave camel-case just for clarity
if study_hours is None:
    print("Invalid grade")
Also, you can convert variables to lowercase in if-conditions, e.g.
Instead of coding

if some_var == 'a' or some_var == 'A':
    ...
you can do:

if some_var.lower() == 'a':
   ...
Reply


Messages In This Thread
RE: Collecting Average User Statistics? 1st semester programmer - by scidam - Mar-05-2020, 11:14 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Rock, Paper, Scissors Advanced that saves, loads, and keeps statistics EvanCahill 0 5,253 Jul-21-2018, 07:32 PM
Last Post: EvanCahill
  Statistics from text file Zatoichi 1 4,288 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