-1

I am struggling with how to put the percentages for the input questions as mentioned in calculatedNumber=score(lab_percent) if that's even correct at all, or is there another string I should be looking at to catch the right percentage for the questions?

Here's my run

def score(earnedPercent, overallWeight):
    scorePercent = earnedPercent // 100
    scorePercent = overallWeight // 100
    scorePercent = scorePercent % 7
    return scorePercent

def grade(gradePercent):
   if gradePercent >=90 and gradePercent <= 100:
      letterGrade="A"
   elif gradePercent >=75 and gradePercent <= 90:
      letterGrade="B"
   elif gradePercent >= 60 and gradePercent <= 75:
      letterGrade = "C"
   elif gradePercent >= 50 and gradePercent <= 60:
      letterGrade = "D"
   elif gradePercent < 50:
      letterGrade = "F"
   return letterGrade

lab_percent=int(input("What is your lab percent so far (-1 if no labs yet)?: "))
calculatedNumber = score(lab_percent)

assignment_percent=int(input("What is your assignment percent so far (-1 if no assignment yet?: "))
calculatedNumber = score(assignment_percent)
exam_percent=int(input("What is your exam percent so far (-1 if no exams yet)?: "))
calculatedNumber = score(exam_percent)

earnedPercent = gradePercent
earnedPercent = earnedPercent.upper()

message='If things keep going the way they are, you should get a ' + earnedPercent + 'in the course, which is a.'

print(message)
quamrana
  • 37,849
  • 12
  • 53
  • 71
KPS
  • 27
  • 6
  • Hello, I think you could [simplify](https://idownvotedbecau.se/toomuchcode/) the code you're presenting to contain only the bare minimum needed to illustrate your issue. – Corentin Pane Nov 08 '19 at 15:48
  • Possible duplicate of [Asking the user for input until they give a valid response](https://stackoverflow.com/questions/23294658/asking-the-user-for-input-until-they-give-a-valid-response) – Sayse Nov 08 '19 at 15:49
  • @Corentin Pane I posted the entire code because it's related to what I am asking about my issue, whether if I should be putting the def grade(gradePercent) or def score(earnedPercent, overallWeight) for the input in score(lab_percent) as a example? Or am I completely incorrect? – KPS Nov 08 '19 at 15:51
  • 1
    The `return` statement of `score()` isn't indented properly. `score()` requires a second parameter that isn't provided in the calls; I don't know where that should come from. Other than that, I don't really understand what you're asking. – Fred Larson Nov 08 '19 at 15:51
  • @FredLarson, could you clarify more on the second parameter? My question is how do I set up the input to put the percentage at the end of the questions? For example: What is your assignment percent so far (-1 if no assignment): 50% then calculate the whole thing within the earnedPercent statement in the print message. – KPS Nov 08 '19 at 15:54
  • 1
    You have `def score(earnedPercent, overallWeight):`, but you call it with `score(lab_percent)` and `score(exam_percent)`. The function requires two parameters, but you're only giving it one. Python won't like that. And `earnedPercent` is assigned to something that isn't defined in that scope, so I'm not sure what to tell you about that. – Fred Larson Nov 08 '19 at 15:59
  • @katie: To get anywhere with this question on this site you need to remove the `grade()` function (you don't use it) and everything below `calculatedNumber = score(lab_percent)` and post the Traceback that will occur and ask why you get the error you have just posted. – quamrana Nov 08 '19 at 15:59
  • @quamrana: Maybe not calling `grade()` is part of the problem. – Fred Larson Nov 08 '19 at 16:00
  • I think that not calling `grade()` is the `last` part of this gordian knot – quamrana Nov 08 '19 at 16:02
  • @FredLarson Ah, I see the issue now. How could I fix the function by giving it two parameters? Do I remove `scorePercent = earnedPercent` and `scorePercent = overallWeight` and replace it with something else? What do I replace `score(lab_percent)` with? I'm extremely new to programming so I'm trying to learn as I go, thank you for the reply! – KPS Nov 08 '19 at 20:19
  • @katie: Perhaps its time for a brand new question. Make it focused this time. There's no limit on the number of questions you can post. Just do it with one per post. – quamrana Nov 08 '19 at 21:00
  • Please don't edit this question. Ask a new one. There is an `Ask Question` button just to the right of the title of this question. – quamrana Nov 08 '19 at 21:23

1 Answers1

1

This is too long for a comment, so I'll point out a few things and give some next steps to help you solve your issue and improve your question on this site for now and the future:

First there are a few errors in your code:

  1. return scorePercent should be indented to be part of the score function.
  2. score requires a second argument overallWeight but you do not pass this in when you call it
  3. In score you assign the value of scorePercent three times - only the last performed assignment will define what scorePercent is.
  4. grade is never called - possibly part of the issue

You will need to fix these errors, then consider more what exactly you are doing in calculating the score. If you are a beginner I would recommend using a text editor or IDE that has IntelliSense so it can warn you about these errors and help you solve them as you go.

Then once you are getting errors out of the way, you can use StackOverflow to ask more specific questions such as "How do I format this output to have a %" for example. The code you posted does not run, and there is no specific question so it is harder for the community to help you solve your problem.

If you fix those errors and edit your post to have a more specific question I will edit my answer to better help as well. Also keep in mind that it can be helpful to use a debugger or just print out values throughout your code to track what things are and see if they are coming out as what you'd expect.


Two arguments in function

When you define a function as you have here, you've set it to take two inputs already: def score(earnedPercent, overallWeight): takes earnedPercent and overallWeight as inputs. So when you call (use) score it needs these two values. Going to where you call it:

calculatedNumber = score(lab_percent)

You only give it one of the parameters, you need to give it another. Say I had lab_weight = 0.2 then I could say:

lab_score = score(lab_percent, lab_weight)

Then you can use this lab_scoreelsewhere.

Scope

For grade, you don't want to delete it - the problem is you just aren't using it. Later in your code you say earnedPercent = gradePercent but gradePercent is only defined in the scope of your grade function. You need to think of each function as its own black box, you can only give it inputs and get out whatever it returns.

I really suggest using some sort of editor with Python IntelliSense so that these errors are pointed out for you as you write code. It also might be helpful for you to look at a tutorial like this on scope so you can get a more in depth explanation of this as it is really really important when you're learning to code.

Incremental Building

Also, consider doing things piece by piece. You have a decent amount of code here but there are errors throughout and its going to take time to track all of them down. For example, write your score function give it an input and print the result. If it's what you expect, then do it again and assign it to a variable, print. Then do it with another variable (you tend to overwrite your variables a lot so this will help you resolve that). Do it step by step and learn through the process and you'll find you can rebuild this code and get it running while also getting more practice and better understanding.

ufoxDan
  • 609
  • 4
  • 13
  • Thank you for the detailed reply! How can I require a second argument with `overallWeight`? Do I type in 'scorePercent = overallWeight' and remove the first two values in that statement? I'm extremely new to programming so I'm trying to learn as I go. And as for 4, do I remove the grade in the def statement then? – KPS Nov 08 '19 at 20:15
  • I will edit my answer with some more details on these specifics – ufoxDan Nov 08 '19 at 20:33
  • For the function, do I use it as labScore=score(labPercent, labWeight,0.20) or something like calculatedNumber(labPercent,0.20) as the lab weight would be 20? – KPS Nov 08 '19 at 21:03
  • If you do `labWeight = 0.2` then you can do `labScore = score(labPercent, labWeight)` because you've now defined `labWeight`. `labScore = score(labPercent, labWeight, 0.20)` won't work because you're passing three arguments in to a function that only takes two. – ufoxDan Nov 08 '19 at 21:16
  • Please reread my comment. You must first define `labWeight` in order to use it. – ufoxDan Nov 08 '19 at 22:10