#πŸ”’ (Big newbie) Single numbers seem to be reading higher than double-digit numbers.

15 messages Β· Page 1 of 1 (latest)

azure tulipBOT
#

@candid root

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

candid root
#

I messed up

#

hang on

chrome cradle
candid root
#

Hi all! (Sorry I messed this up the first time)

I've been teaching myself Python in my spare time, and I've hit a bit of a snag with my grading calculator. Double digit numbers work as intended, however single digit numbers trigger conditions I don't want them to.

Here is what I have written:

letters = list()

print ("Please enter the grades, then input q to calculate.")
while(True):
    user_input = input("> ")
    if(user_input.lower() == "q"):
        break
    totals.append(user_input)

for total in totals:
    if total <= "59":
        letters.append("F")
    elif total <= "69":
        letters.append("D")
    elif total <= "79":
        letters.append("C")
    elif total <= "89":
        letters.append("B")
    else:
        letters.append("A")

print("The GPA for your students is: {}".format(letters))```

All double-digit numbers work as intended, however if I input say, 6, it returns a D. 7 returns a C, etc.

Output is here:
```Please enter the grades, then input q to calculate.
> 5
> 6
> 7
> 8
> 9
> 10
> q
The GPA for your students is: ['F', 'D', 'C', 'B', 'A', 'F']

I'm sure it's a simple solution, but if you can point me in the right direction, it would be much appreciated.
Thanks peeps!

azure tulipBOT
#

Hey @candid root!

It looks like you pasted Python code without syntax highlighting.

Please use syntax highlighting to improve the legibility of your code and make it easier for us to help you.

To do this, use the following method:
```py
print('Hello, world!')
```

This will result in the following:

print('Hello, world!')```
You can **edit your original message** to correct your code block.
solar vault
candid root
#

Ah I'm with ya, I see what I've done

chrome cradle
#

here

totals.append(int(user_input))

to convert it to integer

candid root
#

Thank you!

#

And thank you, man!

#

You're both truly wonderful

chrome cradle
#

np, always happy to help a fellow upcomer. respect for self-taught, you've gotten quite far without help

azure tulipBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.