-1

This is the main.py file:

from data import MENU, resources


def display_resources(store):
    print(f"""Water : {store['water']} ml
Milk  : {store['milk']} ml 
Coffee :{store['coffee']} """)


# TODO 1. Print the resources when user gives input of "report"
user_prompt = input("What would you like to have ? (expresso/latte/cappuccino): ").lower()
if user_prompt == "report":
    print(display_resources(resources))

data.py contains

resources = {
    "water": 300,
    "milk": 200,
    "coffee": 100,
}

When I give "report" as user_prompt, my output loops like:

Water :300ml
Milk  :200ml
Coffee :100g
None

Why does None get printed at the end of the output?

khelwood
  • 55,782
  • 14
  • 81
  • 108

1 Answers1

0

Because you use two print calls. The first in your display function which gives you that you need and the second prints the result of your function but it has no return command so returns None, change your code to this:

from data import MENU, resources

def display_resources(store):
    return f"""Water : {store['water']} ml
Milk  : {store['milk']} ml 
Coffee :{store['coffee']} """


# TODO 1. Print the resources when user gives input of "report"
user_prompt = input("What would you like to have ? (expresso/latte/cappuccino): ").lower()
if user_prompt == "report":
    print(display_resources(resources))
Vovin
  • 720
  • 4
  • 16