Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
'NoneType' error
#6
(Nov-24-2022, 09:30 AM)buran Wrote: Also, note that print() returns None
so a line like this
dollars = print(float(d.lstrip("$")))
will assign None to name dollars and even if you return dollars you still have a problem.

Check also What is the purpose of the return statement? How is it different from printing?

I see your point.
I tried a different approach and this time I get: "can't multiply sequence by non-int of type 'str' ".
I find it hard to understand how to get an output that is non string nor sequence.
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):
    return d.lstrip("$")
    int(d)
  

def percent_to_float(p):
    return p.rstrip("%")
    int(p)  


main()
Yoriz write Nov-25-2022, 08:34 AM:
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,243 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,153 Feb-05-2017, 05:37 AM
Last Post: chelovek
  Regex error: 'NoneType' object has no attribute 'group' DBS 8 29,890 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