Python Forum
Money conversion - problems with lists and .format function
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Money conversion - problems with lists and .format function
#1
money = int(input("How much money do you want to convert: "))
not_quit = True

while not_quit == True:
    money_data = []
    print("The available coins you can convert your money into are: 100p, 50p, 20p, 10p, 5p, 2p, 1p")
    # Enter only a whole integer here without the "P"
    coin = int(input("What coin do you want your money to be converted into: "))
    amount = int(input(
        "How much of this money do you wish to be converted to the coin you have selected: "))

    number_of_coins = amount // coin
    money -= amount

    # I added a string within a string as I could not concatenate the string with the integer variable "coin" unless there is a way around this
    money_data.append([number_of_coins, [coin, "p"]])

    want_to_exit = input(
        "You have {} amount of money left to convert. Do you want to leave? Enter yes to leave, enter no to continue.".format(money))

    want_to_exit = want_to_exit.upper()

    if want_to_exit == "NO":
        not_quit = True
    elif want_to_exit == "YES":
        not_quit = False
        print("You have {}").format(money_data)
AttributeError: 'NoneType' object has no attribute 'format'

My first question is whether money_data[] keeps adding new indexes to its list, and it isn't overwriting itself (keeps adding new information)
My second question is whether we can print lists by using the .format function in the last line of this code.

Thanks
Reply
#2
Line 27: you're calling format on the return value of print, which is of course None. You want to call it on the string instead.

Also, in future, please make sure to include the full traceback of the error - it contains useful information about the error, like the line number.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  .format function Menthix 6 1,639 Mar-12-2022, 10:32 AM
Last Post: stevendaprano
  Use ranking function for different lists klatlap 6 1,966 Feb-15-2022, 11:31 PM
Last Post: klatlap
  use of format function barryjo 3 1,647 Feb-01-2022, 08:07 AM
Last Post: menator01
  Date format and past date check function Turtle 5 4,069 Oct-22-2021, 09:45 PM
Last Post: deanhystad
  Pop function for lists jamesaarr 8 2,582 Aug-26-2021, 06:40 PM
Last Post: ndc85430
  Python code for counting money at multiple stores duddey 9 6,021 Oct-16-2020, 01:17 PM
Last Post: bill_z
  Split dict of lists into smaller dicts of lists. pcs3rd 3 2,312 Sep-19-2020, 09:12 AM
Last Post: ibreeden
  multiple number format conversion oli_action 4 2,531 Aug-11-2020, 05:10 AM
Last Post: perfringo
  Reading Multiple Lists Using SUM function dgrunwal 6 3,285 Jun-03-2020, 08:23 PM
Last Post: dgrunwal
  Parquet format conversion problem Bilhardas 1 1,621 Nov-19-2019, 11:06 AM
Last Post: baquerik

Forum Jump:

User Panel Messages

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