Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
'NoneType' error
#9
(Nov-25-2022, 06:34 AM)ndc85430 Wrote: Please can you post code within Python tags?

Remember that once a return statement is hit, execution goes back to the caller of the function. No code in the function after the return is executed.

Which editor are you using? Some of them give you warnings about things like this, so you notice.

First of all thank you! Can you elaborate? I tried many different things but cannot figure out how to take the input of the questions and return a float that is not 'NoneType'. For now I don't even try to eliminate the dollar and percent signs. The code and the error are attached below.

Code:
def main():
    dollars = dollars_to_float(input("How much was the meal? ")) # Recall that input returns a str
    percent = percent_to_float(input("What percentage would you like to tip? "))
    tip = dollars * percent
    print(f"Leave ${tip:.2f}")


def dollars_to_float(d):
     float()
  

def percent_to_float(p):
    float() 


main()
The error:
Error:
tip = dollars * percent TypeError: unsupported operand type(s) for *: 'NoneType' and 'NoneType'
Yoriz write Nov-26-2022, 08:33 PM:

Please post all code, output and errors (in their entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Reply


Messages In This Thread
'NoneType' error - by YL1985 - Nov-24-2022, 02:14 AM
RE: 'NoneType' error - by deanhystad - Nov-24-2022, 04:08 AM
RE: 'NoneType' error - by buran - Nov-24-2022, 09:30 AM
RE: 'NoneType' error - by YL1985 - Nov-24-2022, 11:40 PM
RE: 'NoneType' error - by rob101 - Nov-24-2022, 10:23 AM
RE: 'NoneType' error - by deanhystad - Nov-24-2022, 06:25 PM
RE: 'NoneType' error - by ndc85430 - Nov-25-2022, 06:34 AM
RE: 'NoneType' error - by YL1985 - Nov-26-2022, 06:50 PM
RE: 'NoneType' error - by rob101 - Nov-25-2022, 06:56 AM
RE: 'NoneType' error - by Yoriz - Nov-26-2022, 08:45 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Getting 'NoneType' object has no attribute 'find' error when WebScraping with BS Franky77 2 8,239 Aug-17-2021, 05:24 PM
Last Post: Franky77
  Type error: '>' not supported between instances of 'NoneType' and 'int' spalisetty06 1 11,727 Apr-29-2020, 06:41 AM
Last Post: buran
  Error TypeError: '<=' not supported between instances of 'int' and 'NoneType' kaledhananjay 1 22,864 May-10-2018, 06:39 AM
Last Post: j.crater
  'NoneType' object has no attribute error, when using Kivy Screens chelovek 3 13,150 Feb-05-2017, 05:37 AM
Last Post: chelovek
  Regex error: 'NoneType' object has no attribute 'group' DBS 8 29,883 Oct-31-2016, 06:36 PM
Last Post: DBS

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020