Question

In: Computer Science

Use Python program. Make a list called groceries with the following values: "pineapple", "tangerine", and "peach"....

Use Python program.

  1. Make a list called groceries with the following values: "pineapple", "tangerine", and "peach".
  2. Define these two dictionaries in your program:

stock = {

    "pineapple": 6,

    "peach": 0,

    "tangerine": 32,

    "pear": 15

}

prices = {

    "pineapple": 4,

    "peach": 2,

    "tangerine": 1.5,

    "pear": 3

}

  1. Take one argument “item” as input from the user and returns the cost of that item. Assume the user will only input an item that exists.
  2. Change the program now so that it takes two separate inputs from the user, ‘item’ and ‘quantity’, and return the cost of that quantity of items. If there are not enough items available, return an appropriate message indicating the quantity that is available, and what that cost is. If the user asks for an item that doesn’t exist, print a message so indicating, and end the program.
  3. Change your program so that it presents the user with a menu of options; ‘enter item and quantity’ and ‘quit’. Cause the program to continue asking for an item and quantity until the user decides to end the program. Apply the same rules as in ‘b’, but each time you return a cost, reduce the amount of available stock by that amount.

Solutions

Expert Solution

CODE:

#instructions
groceries = ['pineapple','tangerie','peach']
stock = {"pineapple": 6,"peach": 0,"tangerine": 32,"pear": 15}
prices = {"pineapple": 4,"peach": 2,"tangerine": 1.5,"pear": 3}
#inifinte loop
while(True):
#printing the menu
print('Enter 1 to enter item and quantity')
print('Enter 2 to quit')
#user entering the choice
choice = int(input())
#if choice == 1
if(choice == 1):
#user enters the item and quantity
item = input('Enter the item: ')
quantity = int(input('Enter the quantity: '))
#if the item is not in the list
if(item not in stock.keys()):
#prints the message
print('Item not in stock!')
else:
#if it is available in the list
#but the quantity entered is greater than
#the quantity available
if(quantity > stock[item]):
#prints the quantity available and price of that qty
print('Quantity entered is greater than available')
print('Quantity available is '+str(stock[item]))
print('Price for that quantity is: $'
+str(stock[item]*prices[item]))
else:
#if user entered a valid quantity
#printing the cost of that quantity
print('Cost of {} {} is: ${}'
.format(str(quantity),item,str(prices[item]*quantity)))
#reducing the amount from the stock
stock[item] -= quantity
elif(choice == 2):
break
else:
print('Invalid Choice!')

_______________________________________________

CODE IMAGES:

_____________________________________________

OUTPUT:

_______________________________________________

Feel free to ask any questions in the comments section

Thank You!


Related Solutions

Using Python, write a program that meets the following requirements: Make a list called sandwich_orders and...
Using Python, write a program that meets the following requirements: Make a list called sandwich_orders and fill it with the names of various sandwiches. Make an empty list called finished_sandwiches. Loop through the list of sandwich orders and spring a message for each order such as "I am working on your tuna sandwich" As each sandwich is made, move it to the list of finished sandwiches. After all the sandwiches have been made, print a message listing each sandwich that...
Write a Python program that performs the following list operations. Part A Define a list called...
Write a Python program that performs the following list operations. Part A Define a list called numList with elements. 84, 94, 27, 74, 19, 90, 16, 21, 56, 50, 77, 59, 41, 63, 18, 26, 80, 74, 57, 30, 40, 93, 70, 28, 14, 11, 43,65, 91, 83, 22, 53, 74, 44, 73, 55, 47, 74, 81 Display the followings: All the numbers in numList The number of elements in numList The smallest number in numList The largest number in...
use python 1. Write a program that a. defines a list of countries that are members...
use python 1. Write a program that a. defines a list of countries that are members of BRICS (Brazil, Russia, India, China, Sri Lanka) b. Check whether a country is a member of BRICS or not Program run Enter the name of country: Pakistan Pakistan is not a member of BRICS Enter the name of country : India India is a member of BRICS 2. Write a program to create a list of numbers in the range of 1 to...
programming in python Design a program that initializes a list of 5 items to zero (use...
programming in python Design a program that initializes a list of 5 items to zero (use repetition operator). It then updates that list with a series of 5 random numbers. The program should find and display the following data: -The lowest number in the list - Average of the numbers stored in the list
Write a program in python such that There exists a list of emails List Ls =...
Write a program in python such that There exists a list of emails List Ls = ['[email protected]','[email protected]','[email protected]','[email protected]',[email protected]'] Count the number of emails IDS which ends in "ac.in" Write proper program with proper function accepting the argument list of emails and function should print the number of email IDs and also the email IDS ending with ac.in output 2 [email protected] [email protected] ================================= i am trying like this but getting confused len [True for x in Ls if x.endswith('.ac.in')] please write complete...
USE Python 2.7(screen shot program with output) the task is: takes in a list of protein...
USE Python 2.7(screen shot program with output) the task is: takes in a list of protein sequences as input and finds all the transmembrane domains and returns them in a list for each sequence in the list with given nonpolar regions and returns the lists for those. 1. This code should call two other functions that you write: regionProteinFind takes in a protein sequence and should return a list of 10 amino acid windows, if the sequence is less than...
In Python Create a function called ℎ?????. The function has as arguments a list called ??????...
In Python Create a function called ℎ?????. The function has as arguments a list called ?????? and a list call center. • List ?????? contains lists that represent points. o For example, if ?????? = [[4,2], [3,2], [6,1]], the list [4,2] represents the point with coordinate ? at 4 and y coordinate at 2, and so on for the other lists. Assume that all lists within points contain two numbers (that is, they have x, y coordinates). • List ??????...
Write a Python program for the following: A given author will use roughly use the same...
Write a Python program for the following: A given author will use roughly use the same proportion of, say, four-letter words in something she writes this year as she did in whatever she wrote last year. The same holds true for words of any length. BUT, the proportion of four-letter words that Author A consistently uses will very likely be different than the proportion of four-letter words that Author B uses. Theoretically, then, authorship controversies can sometimes be resolved by...
1. Write a python program to create a list of integers using random function. Use map...
1. Write a python program to create a list of integers using random function. Use map function to process the list on the expression: 3x2+4x+5 and store the mapped elements in another list. Now use filter to do sum of all the elements in another list. 2. Write a function that takes n as input and creates a list of n lists such that ith list contains first 10 multiples of i. 3. Write a function that takes a number...
Write a python program using the following requirements: Create a class called Sentence which has a...
Write a python program using the following requirements: Create a class called Sentence which has a constructor that takes a sentence string as input. The default value for the constructor should be an empty string The sentence must be a private attribute in the class contains the following class methods: get_all_words — Returns all the words in the sentence as a list get_word — Returns only the word at a particular index in the sentence Arguments: index set_word — Changes...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT