Make a request

Write a program which requests that requests a product name and a stock number . Store that data in a List or a Dictionary . After the user has entered data, request that the user enters Y or N to continue. If they enter N, print the list of products and stock numbers to the screen. If they enter Y, repeat the first step.

Your program should produce the following result:


Stock Manager


Product Name: Widgets
Stock Level: 14
Widgets has been entered with a stock of 14 products.

Do you wish to enter another record? (Y/N) Y

Product Name: Fidgets
Stock Level: 22
Fidgets has been entered with a stock of 22 products.

Do you wish to enter another record? (Y/N) N


Product Stock

Widgets 14
Fidgets 22

Hi the above is my assignment.
However, I have no idea what it really want me to do… as I only learn things from codeacademy
The most confusing is that how to make a request for entry data and how to proceed to show the data on the screen?
Any hit for me be to very appreciated. Thanks

If this is an assignment from some sort of course you’re taking, then the course must have covered the topics of prompting a user for input as well as printing output, no?

Regarding “requesting” input from the user you’ll want to use Python’s built-in input function (see https://docs.python.org/3/library/functions.html#input).

Regarding printing, use the built-in print function (see https://docs.python.org/3/library/functions.html#print).

Here’s a bit of pseudo-code to help out:

repeat = True
inventory = an empty dictionary

while repeat:
    product = request input for "Product Name: "
    stock = request input for "Stock Level: " and convert to an integer
    add product with stock to inventory
    print message "<product> has been entered with a stock of <stock> products."
    repeat = request input for "Do you wish to enter another record? (Y/N) " in ['y', 'Y']

print "Product Stock"

for each product, stock in inventory:
  print product and stock

See also the int function (https://docs.python.org/3/library/functions.html#int) and dictionaries (https://docs.python.org/3/tutorial/datastructures.html#dictionaries)

1 Like

cheers bro!
You made me a day, really.