Presentation is loading. Please wait.

Presentation is loading. Please wait.

Example Programs.

Similar presentations


Presentation on theme: "Example Programs."— Presentation transcript:

1 Example Programs

2 Finding the average score in a list

3 Counting (Tally) items in a list

4 Finding Mobile Phone product details
See speaker notes for code #this is a list that contains product informaton product = ["1262", "Cornflakes", "£1.40", "8743", "Weetabix", "£1.20", "9512", "Rice Krispies", "£1.32"] #stores whether the product has been found found= False #asks the user to enter a product code product_code=input("Enter the product to find: ") #a loop that will repeat for the length of the list for x in range(0,len(product)): #checks if the product code entered matches the current element of the list being checked if product[x] == product_code: #if it is it prints the name and cost print(product[x + 1]) print(product[x + 2]) #sets found to true as the product is found found = True #after the loop checks if the product was not found if found==False: #if it wasn't found it says product not found print("Product not found")

5 Update contact list See speaker notes for code #Create a new list
inventory = ["torch","gold coin","key"] # for loop that outputs the current list print("Current Inventory") for x in range(len(inventory)): print(inventory[x]) #menu that gives the options of what can be done print("What would you like to do? ") print("1. Add an item to the inventory") print("2. Remove an item from the inventory") #gets the user to enter their menu choice option = input(">> ") #if the first option is selected if option == "1": #ask the user to input the item to add item = input("Enter the name of the item you want to add to the inventory: ") #use append to add it to the list inventory.append(item) #if the second option is selected elif option == "2": #ask the user to input the item to remove item = input("Enter the name of the item you want to remove from the inventory: ") #use remove to delete the item from the list inventory.remove(item) #for loop that will output the updated list print("Updated inventory list")


Download ppt "Example Programs."

Similar presentations


Ads by Google