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...
for Python 3 Write a python program that Creates a list that has these values in...
for Python 3 Write a python program that Creates a list that has these values in this order, 'Python', 'JavaScript', and 'PHP' Define a displayMyClasses function that sorts the list and then displays each item on the list, one per line, in sorted order. Also, number the displayed list as shown in the "Running a Sample Program" shown below. Define a guessNext function that selects a random element from the list and returns it to the call of the function....
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...
Write a Python 3 program called “parse.py” using the template for a Python program that we...
Write a Python 3 program called “parse.py” using the template for a Python program that we covered in this module. Note: Use this mod7.txt input file. Name your output file “output.txt”. Build your program using a main function and at least one other function. Give your input and output file names as command line arguments. Your program will read the input file, and will output the following information to the output file as well as printing it to the screen:...
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
Chapter 6: Use a list to store the players Update the program in python so that...
Chapter 6: Use a list to store the players Update the program in python so that it allows you to store the players for the starting lineup. This should include the player’s name, position, at bats, and hits. In addition, the program should calculate the player’s batting average from at bats and hits. Console ================================================================ Baseball Team Manager MENU OPTIONS 1 – Display lineup 2 – Add player 3 – Remove player 4 – Move player 5 – Edit player...
Chapter 6: Use a list to store the players In Python, Update the program so that...
Chapter 6: Use a list to store the players In Python, Update the program so that it allows you to store the players for the starting lineup. This should include the player’s name, position, at bats, and hits. In addition, the program should calculate the player’s batting average from at bats and hits. Console ================================================================ Baseball Team Manager MENU OPTIONS 1 – Display lineup 2 – Add player 3 – Remove player 4 – Move player 5 – Edit player...
Please use Python for both Concatenate List Elements Write a function called concat_list that accepts a...
Please use Python for both Concatenate List Elements Write a function called concat_list that accepts a list of strings as an argument and returns a string made up of all elements in the list concatenated together in order. For example, if the argument is ['one', 'two', 'three'], the return value would be 'onetwothree'. Remove List Duplicates Write a function called remove_duplicates that accepts a list and returns a list containing the same elements in the same order but with duplicates...
Write a Python program in a file called consonants.py, to solve the following problem using a...
Write a Python program in a file called consonants.py, to solve the following problem using a nested loop. For each input word, replace each consonant in the word with a question mark (?). Your program should print the original word and a count of the number of consonants replaced. Assume that the number of words to be processed is not known, hence a sentinel value (maybe "zzz") should be used. Sample input/output: Please enter a word or zzz to quit:...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT