This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm whether you accept or reject these cookies being set.

A cookie will be stored in your browser regardless of choice to prevent you being asked this question again. You will be able to change your cookie settings at any time using the link in the footer.

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python Product Finder
#1
Code:
#productid,productname,product price
products = [
"1262", "Coco Pops", 4.00, 
"8743", "Sugar Puffs", 3.60, 
"9512", "Rice Krispies", 3.90
]
product_found = -1

product_code=input("Enter the product code that you want to find: ")

for i in range(0,len(products),3):
    if products[i] == product_code:
           product_found =  i
if product_found != -1:
    print(products[product_found + 1])
    print(products[product_found + 2])
else:
    print("not found")
Disclaimer: Don't be misguided looking at my usergroup and assume whatever I say is official. When I speak in community I am just a member with personal opinions.
Reply


Messages In This Thread
Python Product Finder - by jamie - 12/07/2018, 05:43 PM

Forum Jump:


Users browsing this thread: 2 Guest(s)
www.000webhost.com