-7

Consider the following data:

3.85,4.89,2.89,1.02.3.8.3.7,2.9,2.5,3.3,3.59

Which represents the GPA of the following students respectively

"Sia". "Rihanna", "Taline". "Donald", "Sabra","Stefanie","Tome","Jim","Kalim","Wu"

Write a python program that does the following

  1. Save the values in Tuple called studentGrade.
  2. Compare the GPA and find the maximum grade.
  3. Print the student's name who has the maximum grade.
  4. Find out the average GPA.
  5. Find out the Standard Deviation of the grades
  6. Calculate the median of the GPA
  7. Which student failed the exam (must score more than 4.1)

Here's my current code

gpa=[3.85,4.89,2.89,1.02,3.8,3.7,2.9,2.5,3.3,3.5]
sortedgrade= sorted(gpa)
print(gpa)

names=['sia','Rihanna','taline','Donald','sarah','stefanie','tome','jim','kalim','wu']

studentgrade=(gpa,names)

max=gpa[0]

for i in range (0,len(gpa)):

    if gpa[i]<max:

        max=gpa[i]

        b=i

        a=max

print(f'max grade =',a)

print(f'{names[b]} scored maximum grade')
ti7
  • 16,375
  • 6
  • 40
  • 68
  • 4
    Welcome to SO! What have you tried so far? We're much more here to help with specific questions of the form "I tried X, but it did not do what I expect and instead resulted in an error!" accompanied by a [Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve) – ti7 Feb 01 '22 at 17:48
  • @ti7 I have solved the question without any running errors only problem I have is that the grades are not matching the right names. – Sukhman Sandhu Feb 01 '22 at 18:13
  • 1
    this is clearly an assignment due to its structure (asking about homework is permitted, but you should understand what is expected from you here https://meta.stackoverflow.com/questions/334822/how-do-i-ask-and-answer-homework-questions ) please post your code then! you can use three back-tick marks ` to create a code block or use the built-in formatter (a preview of your post appears under it before pressing go) .. I've modified your post as an example .. at an absolute minimum, you should include your attempted work and attempt to correctly format your post – ti7 Feb 01 '22 at 18:19
  • @SukhmanSandhu everyone started somewhere - please simply format your question nicely with needed details, such as where you believe some problem is, any traceback, which of the N questions you are having trouble with (ie. the first one?), the output of your code .. how can a malformed Question have anything but a malformed Answer? with the code added, I've attempted to fix the formatting, and we can understand what's wrong! – ti7 Feb 01 '22 at 19:43
  • The first version of your "question" was a pure copy&paste assignment dump. No problem statement, no effort, no code, no formatting, no question. No explanation what you did, no [mre], no following of [ask]. Also no filling out of the question template new ones get shown. No research. I was merely asking you if you are allowed to do that to fullfill your requirements. Nobody here wants to "copyright knowledge" - if, we would not participate. – Patrick Artner Feb 01 '22 at 20:07
  • @PatrickArtner is exactly correct - however, with the addition of the code there's enough information to figure out what's wrong and make an initially hopeless question (specifically without _any_ clear attempt to build on) much more hopeful! – ti7 Feb 01 '22 at 20:10
  • 1
    practically anytime - the general problem with copy-and-paste assignment questions is that it's impossible to meaningfully help the author and the community without more information on _what they've done to solve the problem_ to _help them get further_ .. simply "a problem exists!" is occasionally interesting, but almost-always useless to everyone involved and a waste of experts' time either trying to understand a Question or preparing an elegant solution which can't be used or isn't understood [How do I ask a good question?](https://stackoverflow.com/help/how-to-ask) has a good overview – ti7 Feb 01 '22 at 20:27
  • 1
    @ti7 i appreciate the guidance – Sukhman Sandhu Feb 01 '22 at 20:29
  • Right click the "Ask a question" and open it in a new tab. Do you see the sidebar? 3 Steps: **Summarize the problem:** Include details about your goal / Describe expected and actual results / Include any error messages; **Describe what you tried:** Show what you’ve tried and tell us what you found and why it didn’t meet your needs. You can get better answers when you provide research. **Show some code** with a link to [mre]. Directly below that: **more helpful links** with a link to [ask]. You choose to copy&paste a problem dump and ignore all of it. Call me rude. Im out. – Patrick Artner Feb 01 '22 at 20:38

1 Answers1

-1

The problem is that when you sort the GPAs, they're no longer associated with the name ordering - you can simply skip doing so and the list indicies will stay correct or bring them into some collection (the instructions actually specify a tuple)

# starting values
scores_GPA = [3.85, 4.89, 2.89, 1.02, 3.8, 3.7, 2.9, 2.5, 3.3, 3.5]
names = ["Sia", "Rihanna", "Taline", "Donald", "Sabra", "Stefanie", "Tome", "Jim", "Kalim", "Wu"]
# no need to sort

The instructions also likely mean to keep the values paired in a tuple, rather than having two individual tuples

simple tuple

>>> (names, scores_GPA)
(['Sia', 'Rihanna', 'Taline', 'Donald', 'Sabra', 'Stefanie', 'Tome', 'Jim', 'Kalim', 'Wu'], [3.85, 4.89, 2.89, 1.02, 3.8, 3.7, 2.9, 2.5, 3.3, 3.5])

tuple of tuples, maintaining the positions (likely intention)

>>> tuple(zip(names, scores_GPA))
(('Sia', 3.85), ('Rihanna', 4.89), ('Taline', 2.89), ('Donald', 1.02), ('Sabra', 3.8), ('Stefanie', 3.7), ('Tome', 2.9), ('Jim', 2.5), ('Kalim', 3.3), ('Wu', 3.5))

Now you can iterate by-items, getting pairs together!

>>> name_gpa_tuple = tuple(zip(names, scores_GPA))
>>> for name, gpa in name_gpa_tuple:  # NOTE this unpacks the inner tuple!
...    print(name, gpa)
...
Sia 3.85
Rihanna 4.89
Taline 2.89
Donald 1.02
Sabra 3.8
Stefanie 3.7
Tome 2.9
Jim 2.5
Kalim 3.3
Wu 3.5

Or more usefully for your example, some structure like this

max_GPA = -1
for name, gpa in name_gpa_tuple:
    if gpa > max_GPA:
        ...

You may also find creating a dictionary of the values is practical (as each name can be a unique key and provides a .items() method to iterate), but this steps outside the directions and may be marked extra for being clever or wrong on an assignment depending on the source's policy
How do I sort a dictionary by value?

ti7
  • 16,375
  • 6
  • 40
  • 68