so iv been trying to write a code that works like a menu creating program that :
1# take the input from user to define the number of products and there names
2# assign prices separately after taking products names from user
2# assign prices separately after taking products names from user
3# display the menu after its done
am a beginner in coding and python language this is how my code is looking after many tries and researches
def functions():
maxlengh = input("how many products in your card ? : ")
maxlengh = int(maxlengh)
select_function = input("press 1 to add product names to the menu or 2 to assign prises : ")
select_function = int(select_function)
products = []
while select_function == 1 and len(products) != maxlengh :
items = input("enter product name : ")
items= items.split()
products.append(items)
if len(products) == maxlengh :
select_function == 2
prise = []
while select_function ==2 and len(prise) != maxlengh :
items = input("enter product prise : ")
items = items.split()
prise.append(items)
menu = dict(zip(products,prise))
print(menu )
CodePudding user response:
Here try this: in Python, indents are very important, and some of yours were a little off. this should work. good luck!
max_length = int(input("how many products in your card ? : "))
select_function = input("press 1 to add product names to the menu or 2 to assign prices : ")
select_function = int(select_function)
products = []
while select_function == 1 and len(products) != max_length :
items = input("enter product name : ")
items = items.split()
products.append(items)
if len(products) == max_length :
select_function == 2
price = []
while select_function ==2 and len(price) != max_length :
items = input("enter product price : ")
items = items.split()
price.append(items)
menu = dict(zip(products,price))
print(menu)
CodePudding user response:
you can use
dic her is your code:
def functions():
maxlengh = int(input("how many products in your card ? : "))
products = [] #[{name:"name",price:"price",}]
for num in range(maxlengh):
product_name=input("inter product name: ")
product_price=input("inter product price: ")
product={"name":product_name,"price":product_price}
products.append(product)
print(products)
return products
functions()