Question

Python: •Write a program to get the Food Menu using an API •The program should be...

Python:

•Write a program to get the Food Menu using an API

•The program should be able to display different food items. If possible, add food prices .

0 0
Add a comment Improve this question Transcribed image text
Answer #1

The assumption for API. Let's say there's an API that on GET call gives us the food menu and further details including food prices.

API gives JSON Response when called with GET Request.

The API Response looks like below.

{

"1": {

"name": "Plain Cold Coffe",

"price": "45"

}

"2": {

"name": "Plain Hot Coffe",

"price": "55"

}

}

And so on... The API could be of any format. The following python program can be used for processing the response and displaying the Food Menu.

import urllib.request, json
print("Food Menu")
requestURL = "https://example-api.com/example-food-menu-api" # Enter API URL Here
with urllib.request.urlopen(requestURL) as url:
    menu = json.loads(url.read().decode())
    for item in menu:

print("Name: "+name+" Price: "+price)

In the above program, we've used two libraries urlbib and JSON. You can modify the code according to your custom requirements. This will simply display the items and their prices on the menu, one item per line.

Add a comment
Know the answer?
Add Answer to:
Python: •Write a program to get the Food Menu using an API •The program should be...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • (PYTHON) Write a program that displays the following menu:. , Write Algorithm for Code Geometry Calculator...

    (PYTHON) Write a program that displays the following menu:. , Write Algorithm for Code Geometry Calculator 1. Calculate the Area of a Circle 2. Calculate the Area of a Rectangle 3. Calculate the Area of a Triangle 4. Quit Enter your choice (1 - 4): If the user enters 1, the program should ask for the radius of the circle and then display its area. If the user enters 2, the program should ask for the length and width of...

  • Please help me to do my assignment it should be python. Thank you Write a menu-driven...

    Please help me to do my assignment it should be python. Thank you Write a menu-driven program for Food Court. (You need to use functions!) Display the food menu to a user (Just show the 5 options' names and prices - No need to show the Combos or the details!) Ask the user what he/she wants and how many of it. (Check the user inputs) AND Use strip() function to strip your inputs. Keep asking the user until he/she chooses...

  • Geometric calclator use python to do this program. Write a program that displays the following menu:...

    Geometric calclator use python to do this program. Write a program that displays the following menu: 1. Calculate the area of circle 2. calculate the area of rectangle 3. calculate the area of triangle 4. Quit Enter your choice (1-4). if the user enters 1, your program should ask for the radius of the circle and then display its area. Use the formula to calculate the circle's area: Area = pi*r^2 Use 3.14149 for Pi and the radius of the...

  • USING A PYTHON Write a program that gives simple math quizzes. The program should display two...

    USING A PYTHON Write a program that gives simple math quizzes. The program should display two random numbers that are to be added, such as: 247 + 129 The program should allow the student to enter the answer. If the answer is correct, a message of congratulations should be displayed. If the answer is incorrect, a message showing the correct answer should be displayed.

  • Can someone do this first function? Using python and API! API KEY:  8bb45882c0894d8c1ad25a8dcc157c09 Function name: get_movie_recommendations Parameters:...

    Can someone do this first function? Using python and API! API KEY:  8bb45882c0894d8c1ad25a8dcc157c09 Function name: get_movie_recommendations Parameters: movie_ids (list of ints) Returns: recommended movie titles (list of strings) Description: Write a function that takes in a list of movie IDs. Find the movies corresponding to the IDs. If the popularity of the movie is greater than 20, add the movie title (string) to a list. Return the list of titles. Note: Your function should be able to handle invalid movie ids....

  • In C++ write a simple menu program that displays a menu for the user in an...

    In C++ write a simple menu program that displays a menu for the user in an object-oriented technique. The menu should keep showing up until the user chooses to quit. Also, there is a sub-menu inside a menu. The user should get at least a line displayed after he or she chooses that particular option meaning if the user presses 1 for the read actors from the file. The output can look like "reading actors from a file" and then...

  • Write a Python program that reads from the user 4 item prices then displays the total...

    Write a Python program that reads from the user 4 item prices then displays the total and average price. The program should also display the taxes ( using the TAX_RATE=8.75) and the total after tax.

  • Write a Python program (using python 3.7.2) that lets the user play the game of Rock,...

    Write a Python program (using python 3.7.2) that lets the user play the game of Rock, Paper, Scissors against the computer. The program should work as follows. 1. When the program begins, a random number in the range of 1 through 3 is generated. If the number is 1, then the computer has chosen rock. If the number is 2, then the computer has chosen paper. If the number is 3, then the computer has chosen scissors. (Don’t display the...

  • Write the PYTHON code that displays the following numbers: The program should have a header that...

    Write the PYTHON code that displays the following numbers: The program should have a header that displays "Number   Doubled Tripled" above the start of the numbers. If putting all numbers on the same line, then they will need to be separated so you can see he individual number.(https://www.programiz.com/python-programming/methods/built-in/print) The program should display Every whole number from 1 through 35. The program should display that number doubled. The program should also display that number tripled. Make a working version of this...

  • Write a program that stores the following data in a tuple: 54,76,32,14,29,12,64,97,50,86,43,12 The program needs to...

    Write a program that stores the following data in a tuple: 54,76,32,14,29,12,64,97,50,86,43,12 The program needs to display a menu to the user, with the following 4 options: 1 – Display minimum 2 – Display maximum 3 – Display total 4 – Display average 5 – Quit Make your program loop back to this menu until the user chooses option 5. Write code for all 4 other menu choices using the python code and screenshot the python code for me. many...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT