In this Python list program, we will take a user input as a list and calculate the bill per fruit purchased from a given fruit list with the help of the below-given steps.
Bill per fruit purchased:
Steps to solve the program
- Take a list of fruits and their prices as input.
- Calculate the bill per fruit purchased using for loop.
- Print the output.
#Input lists
list1 = [["apple", 30], ["mango", 50], ["banana", 20], ["lichi", 50]]
list2 = [["apple", 2],["mango",10]]
for value in list1:
for var in list2:
if value[0] == var[0]:
#Printing output
print("Fruit: ", value[0])
print("Bill: ", value[1]*var[1])
Output :
Fruit: apple
Bill: 60
Fruit: mango
Bill: 500
Related Articles
Python program to calculate percentage from a given mark list, the max mark for each item is 100.
Python program to get the list of all palindrome strings from the given list.
Python program to flatten a given nested list structure.
Python program to convert tuples in the list into a sublist.
Python program to create a dictionary from a sublist in a given list.
Python program to replace ‘Java’ with ‘Python’ from the given list.