-2

Pretty much I'm trying to make a GPA calculator. I don't want anyone to just do the whole thing for me because I'm trying to figure out how to get 8 different values from the user in one line and add them together into one value. Most of the answers I've found online only talk about adding 2 values together so it's not of very much use to me...

I've tried using the ".split" function but really that's about it I'm new to python and dont have the background knowledge to really try much else.

No code, just need help with this problem

The expected result is to ask the user to put in 8 different grades between 0 and 100, then add them together into one value to later be divided.

  • 1
    SO isn't really a tutoring site. Perhaps you can show us what you have so far and describe exactly what you're stuck on. We can help you get over your current roadblock, then you can proceed from there. If you run into another issue, you can ask a new question for that. – glibdud Jun 11 '19 at 15:48
  • There are at least 4 steps in the process you describe (get input, split, convert to numbers, sum), so which step are you stuck on? Please post your code, or at least your best attempt. See [ask] for more tips. – wjandrea Jun 11 '19 at 15:58
  • When asking about homework (1) Be aware of your school policy: asking here for help may constitute cheating. (2) Specify that the question is homework. (3) Make a good faith attempt to solve the problem yourself first (include your code in your question). (4) Ask about a specific problem with your existing implementation; see [Minimal, complete, verifiable example](https://stackoverflow.com/help/minimal-reproducible-example). Also, [here](https://meta.stackoverflow.com/questions/334822/how-do-i-ask-and-answer-homework-questions) is guidance on asking homework questions. – Prune Jun 11 '19 at 16:06

2 Answers2

1

If the GPAs come in in this format:

'3.3 3.6 2.7'

then you can read it in like this:

gpas = input('Please enter the GPAs in one line separated by spaces').split(' ')

and then you can loop through them (since split() returns a list), convert them to floats, and add them up, like so:

sum = 0
for gpa in gpas:
  sum += float(gpa)
manny
  • 338
  • 1
  • 11
  • `str.split` won’t convert the numbers to `float`. Your output will be something like `3.33.62.7`. – N Chauhan Jun 11 '19 at 15:59
  • You're totally right! I edited my answer to include the float conversion. Thanks for that catch. – manny Jun 11 '19 at 16:00
-1

From what I read, I see you're getting the user's input as a string, from what you want to get the numbers the user entered and then operate with them, your problem being getting each separate number from the input. I think this other question on SO may help. Once you get each 'word' as an element of the array, you should convert each element to an int, getting the desired result.

Hope this helps!

89f3a1c
  • 1,430
  • 1
  • 14
  • 24