#🔒 Help with code i got a TypeError (brand new to python/coding)

26 messages · Page 1 of 1 (latest)

verbal surge
#

Hi,
I am trying to complete the PY4E course and I am having trouble figuring out the correct code.

I got a TypeError ‘<=’ not supported between instances of ‘str’ and ‘int’ on line 6

THIS IS THE CODE

  1. hrs = input(“Enter Hours”)
  2. rat = input(“Enter Rate”)
  3. reg = 40
  4. ovt = 1.5
  5. check = float(hrs) * float(rat)
  6. if hrs <= 40 :
  7.     print(check)
    
  8. print(check)
  9. ovtpay = (float(hrs) - float(reg)) * (float(rat) * float(ovt))
  10. if hrs > 40 :
  11.     print(ovtpay)
    

12.print(ovtpay)

craggy surgeBOT
#

@verbal surge

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.

verbal surge
#

i expect to input 45 for hours and 10.50 for rate then the code will do the math and i will get an output of 498.75

blazing nymph
#

can you format your code or paste it to the pastebin?

#

!paste

craggy surgeBOT
#
Pasting large amounts of code

If your code is too long to fit in a codeblock in Discord, you can paste your code here:
https://paste.pythondiscord.com/

After pasting your code, save it by clicking the Paste! button in the bottom left, or by pressing CTRL + S. After doing that, you will be navigated to the new paste's page. Copy the URL and post it here so others can see it.

blazing nymph
#

!code

craggy surgeBOT
#
Formatting code on Discord

Here's how to format Python code on Discord:

```py
print('Hello world!')
```

These are backticks, not quotes. Check this out if you can't find the backtick key.

For long code samples, you can use our pastebin.

blazing nymph
#

none of your stuff is indented right now. I'm assuming the line numbers are from something else right?

eager vapor
bronze bloom
verbal surge
verbal surge
bronze bloom
#

Or yes? I think I misread, but you should convert both hrs and rat to a float or int depending on your needs. Just don't leave them as strings.

verbal surge
#

on line 6 and 7 they are str correct?

verbal surge
bronze bloom
#

Yes.

verbal surge
#

once i change it to an int i get the same error message, most likely because i am still doing something wrong or misunderstanding. Apologies this is my second day doing this.

bronze bloom
# verbal surge once i change it to an int i get the same error message, most likely because i a...

That's the wrong one. 40 is already an int, hrs is the string that needs to be converted into a numeric type. In the style of a rust error, ```py
hrs = input("Enter Hours")
rat = input("Enter Rate")
reg = 40
ovt = 1.5
check = float(hrs) * float(rat)
if hrs <= int(40) :

^^^

variable hrs is of type str, which cannot be compared with int.

Consider converting hrs to a numerical type

ie. float(hrs) <= 40 or int(hrs) <= 40

print(check)

print(check)
ovtpay = (float(hrs) - float(reg)) * (float(rat) * float(ovt))
if hrs > int(40) :

^^^

variable hrs is of type str, which cannot be compared with int.

Consider converting hrs to a numerical type

ie. float(hrs) > 40 or int(hrs) > 40

print(ovtpay)

print(ovtpay)```

verbal surge
#

For the assignment I have to input 45 and the rate input as 10.50

#

nvm i did i thank you

craggy surgeBOT
#
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.