1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Katyanochek1 [597]
3 years ago
6

Write a program get_price.py with a function get_price() that takes a dictionary of fruits as an argument and returns the name o

f the most expensive fruit. Each item of the dictionary includes: A key: the name of the fruit A value: the price of the fruit.
Computers and Technology
1 answer:
yawa3891 [41]3 years ago
4 0

Answer:

The program is as follows:

def get_price(fruits):

   AllPrice = fruits.values()

   value_iterator = iter(AllPrice)

   mostExpensive = next(value_iterator)  

   for item in fruits:

       if fruits[item]>=mostExpensive:

           mostExpensive = fruits[item]

           fruitName = item

   print(fruitName)

fruits = {}

n = int(input("Number of Fruits: "))

for i in range(n):

   name = input("Fruit name: ")

   price = int(input("Fruit price: "))

   fruits[name] = price

get_price(fruits)

Explanation:

This defines the get_price function

def get_price(fruits):

This gets all price in the dictionary fruit

   AllPrice = fruits.values()

This passes the values to a value iterator

   value_iterator = iter(AllPrice)

This initializes mostExpensive to the first price in the dictionary

   mostExpensive = next(value_iterator)

This iterates through the elements of the dictionary  

   for item in fruits:

If current element is greater than or equals most expensive

       if fruits[item]>=mostExpensive:

Set most expensive to the current element

           mostExpensive = fruits[item]

Get the corresponding fruit name

           fruitName = item

Print fruit name

   print(fruitName)

The main begins here

This initializes the fruit dictionary

fruits = {}

This gets input for the number of fruits

n = int(input("Number of Fruits: "))

This is repeated for every inputs

for i in range(n):

Get fruit name

   name = input("Fruit name: ")

Get fruit price

   price = int(input("Fruit price: "))

Append name and price to dictionary

   fruits[name] = price

Call the get_price function

get_price(fruits)

You might be interested in
Which excel feature makes it easy to copy and paste formulas in multiple cells?.
timama [110]

Answer:

Ctrl + R - Copy a formula from the cell to the left and adjusts the cell references. For example, if you have a formula in cell A2 and you want to copy it to cell B2, select B2 and press Ctrl + R. Tip. Both of the above shortcuts can be used to copy formulas to multiple cells too.

Explanation:

8 0
2 years ago
What is displayed on the console when running the following program?
uranmaximum [27]

I guess there should be the program code in your question. I presume that the complete version of your question is the following:

What is displayed on the console when running the following program?

public class Test {

 public static void main(String[] args) {

   try {

     System.out.println("Welcome to Java");

     int i = 0;

     int y = 2 / i;

     System.out.println("Welcome to HTML");

   }

   finally {

     System.out.println("The finally clause is executed");

   }

 }

}

A.  Welcome to Java, then an error message.

B.  Welcome to Java followed by The finally clause is executed in the next line, then an error message.

C.  The program displays three lines: Welcome to Java, Welcome to HTML, The finally clause is executed, then an error message.

D.  None of the above.

Answer to the complete question with explanation:

B.     Welcome to Java followed by The finally clause is executed in the next line, then an error message

After entering <em>try/catch</em> block program will output <em>"Welcome to Java"</em>.

Then <em>ArithmeticException</em> will be raised at line:

<em>int y = 2 / i;</em>

The reason is division by <em>0</em> because <em>i = 0</em>.

After that <em>finally</em> clause will be executed despite exception thrown which will output <em>"The finally clause is executed"</em>.

There could be a chance that you have modified answers to your question. In that case:

Answer to the original question:

a. Welcome to Java,

c. The finally clause is executed, then an error message.

7 0
3 years ago
Why do wireless networks experience such a great reduction in actual throughput compared with their respective theoretical throu
jasenka [17]

Wireless networks experience such a great reduction in actual throughput compared with their respective theoretical throughputs, because wireless networks experience a high number of collisions and require greater overhead on each transmission. The throughput varies significantly from the theoretical maximum speeds due to:

distance from the access point, physical obstructions, such as walls, signal-blocking or reflecting materials which affect signal propagation and reduce speed , interference - other wireless networks and devices in the same frequency in the same area affect performance and shared bandwidth - available bandwidth is shared between all users on the same wireless network.


5 0
3 years ago
Which feature of a word processing program enables you to represent an textual information in the form of a diagram?
irina [24]
A Table is Going Ti Help Us Represent Textual Information In The form of a Diagram
5 0
3 years ago
.- Una tienda de vestidos de fiesta, ofrece un descuento a las personas
elena55 [62]

ajaaaieisslslqlqlqqpqlkek3k2l2ll2llllww

4 0
3 years ago
Other questions:
  • You have implemented a network where each device provides shared files with all other devices, what kind of network is it?
    6·1 answer
  • Which osi reference model layer includes all programs on a computer that interact with the network?
    13·1 answer
  • Which device or software application detects errors in system configurations?
    8·1 answer
  • The Springfork Amateur Golf Club has a tournament every weekend. The club president
    7·1 answer
  • 1.Input device which transfers information and images from physical documents to computer files.
    14·1 answer
  • Name at least TWO kinds of gaming experiences that are possible with these new control devices but were not possible on original
    7·1 answer
  • How to do a linear equations
    8·1 answer
  • What is the purpose the wait block?
    10·1 answer
  • True or False <br> Hebrew Bible and the Koran were first written in English.
    15·1 answer
  • The value that decides whether something falls into one category or another is called a ____
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!