We can also work with user input directly in string form. If the user is supposed to enter a word or other piece of text, it makes no sense to try to convert that to a number. Fortunately, the comparison operators like
==
,
!=
,
>
, etc… all work with strings.
Now it is your turn to write a program that makes decisions with strings. In the program below, your job is to write the function that will turn a letter grade like “A” into the GPA points it is worth: 4. That function will be used to calculate the GPA of someone who took three classes.
Notice that there is some commented out code that
hardcodes in three input values.
Hardcoded values are ones that are written into a program instead of coming from outside as the program runs (like from user input). Sometimes,
hardcoding some values makes it easier to test a function like the one you need to write - you can run the program and immediately see the result instead of having to type in all the inputs every time you run it. Then, once you get the function working, you can remove the hardcoded values and start using real input.