Generation

code to explanationSat, 27 May 2023

Faça um script Python que peça para o usuário registrar um estoque de produtos. Cada produto possui um código, um preço e uma quantidade. O estoque pode armazenar 5 produtos. Depois de receber os 5 produtos do estoque, mostre um relatório com os produtos, a quantidade total de itens (todos os produtos) e o valor total do estoque (de todos os produtos).

#Defining the function def stock(): #Creating a list with the values collected products = [] #Creating a for to make a loop to 5 times for i in range(5): #Adding each product to the list product = {"name": input("What is the product name? "), "price": float(input("What is the product price? ")), "quantity": int(input("How many products are there in the store? "))} products.append(product) #Creating a variable to armazenate the total of quantities quantity_total = 0 #Creating a variable to armazenate the total price price_total = 0 #Creating a for to make a loop to 5 times for i in range(5): #Adding the quantity of each product to the total quantity_total = product['quantity'] + quantity_total for i in range(5): #Adding the price of each product to the total price_total = product['price'] + price_total #Printing

Questions about programming?Chat with your personal AI assistant