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
Dima020 [189]
3 years ago
14

Implement the function printTwoLargest that inputs an arbitrary number of positive numbers from the user. The input of numbers s

tops when the first negative or zero value is entered by the user. The function then prints the two largest values entered by the user. If fewer than two distinct positive numbers are entered a message to that effect is printed instead of printing any numbers. Hint: Duplicates will cause problems. Try to make sure that you find a way to ignore them.
Computers and Technology
1 answer:
meriva3 years ago
3 0

Answer:

The function in Python is as follows:

def printTwoLargest():

   chk = 0

   list1 = []

   num = int(input("Enter: "))

   while num > 0:

       for i in list1:

           if i == num:

               chk+=1

               break;

       if chk == 0:

           list1.append(num)

       chk = 0

       num = int(input("Enter: "))

   list1.sort()

   if len(list1) >= 2:

       print("Largest:", list1[-1])

       print("Second:", list1[-2])

   else:

       print("Length of list must be at least 2")

Explanation:

This defines the function

def printTwoLargest():

This initializes a check variable to 0

   chk = 0

This initializes an empty list

   list1 = []

This prompts the user for input

   num = int(input("Enter: "))

The following loop is repeated until input is 0 or negative

   while num > 0:

<em>The following for loop checks for duplicate</em>

<em>        for i in list1: </em>

<em>            if i == num: </em><em>If duplicate is found</em><em> </em>

<em>                chk+=1 </em><em>The check variable is set to 1</em><em> </em>

<em>                break; </em><em>And the for loop is exited</em><em> </em>

The input is appended to the list if the check variable is 0 (i.e. no duplicate)

<em>        if chk == 0: </em>

<em>            list1.append(num) </em>

This sets the check variable back to 0, for another input

       chk = 0

This prompts the user for another input

       num = int(input("Enter: "))

This sorts the list

   list1.sort()

This prints the two largest if valid user input is 2 or more

<em>    if len(list1) >= 2: </em>

<em>        print("Largest:", list1[-1]) </em>

<em>        print("Second:", list1[-2]) </em>

if otherwise, this prints that the length must be at least 2

<em>    else: </em>

<em>        print("Length of list must be at least 2")</em>

You might be interested in
"Different links can transmit data at different rates, with the _______ of a link measured in bits/second"
murzikaleks [220]

Answer: Transmission rate

Explanation:

 Transmission rate is measured in bits per second and it transmitted the data at the different rate across the circuit. The speed in which the data rate is transferred from one device to anther is known as transmission rate.

The transmission rate are always less as compared to signalling rate because the signalling rate contain the total data which basically include the overhead to control the information.

Therefore, transmission rate is the correct option.

 

7 0
3 years ago
The set of rules for how computers talk to one another is called
lianna [129]
Protocol. Like TCP/IP or HTTP etc
6 0
3 years ago
Porque sophia es un robot mujer?
gregori [183]
Sophia es un robot humanoide (ginoide) desarrollado por la compañía, con sede en Hong Kong, Hanson Robotics. Ha sido diseñada para aprender, adaptarse al comportamiento humano y trabajar con estos satisfactoriamente.
7 0
3 years ago
Which of the following statements about meta tags is TRUE?
Iteru [2.4K]

Answer:

I guess c no. is the answer

6 0
3 years ago
Read 2 more answers
Which of the following is an example of an access object?
Julli [10]

Answer:

The Data Access Object pattern is a structural pattern that allows us to isolate the application/business layer from the persistence layer

<h2>I'm not sure but tell me if its right or wrong in order to help others</h2>

Explanation:

4 0
3 years ago
Other questions:
  • In a paragraph of no less than 125 words, describe how you would insert a graph in your word-processing document.
    8·2 answers
  • What does the Flippy Do Pro show about representing very small numbers?
    13·1 answer
  • ____ are systems in which queues of objects are waiting to be served by various servers
    5·1 answer
  • How to cite a website, like asha.org?
    6·1 answer
  • Do you think our attitude (whether positive or negative) is something we are born with or that we have power to control within o
    5·2 answers
  • Which types of operating systems execute program independent of the users and generate output within a specific amount of time?
    5·1 answer
  • Identify at least five different Information Technology careers that you could pursue in your home state, and choose the three t
    10·2 answers
  • A _______ is one typed character.<br> -gigabyte<br> -byte<br> -megabyte<br> -kilobyte<br> -terabyte
    7·1 answer
  • 2
    6·1 answer
  • Help me with this two questions please
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!