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]
2 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:
meriva2 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
41. All the following software are examples of operating systems EXCEPT
Hunter-Best [27]

Answer:

vista

Explanation:

the other three I have used before

8 0
2 years ago
Which of the following statements is true regarding ARPANET? Select 3 options. It was a product of Bell Laboratories and was int
vlada-n [284]

Answer:

2. It was created to connect geographically dispersed researchers with high powered research computers.

3. The first message was sent through ARPANET in 1969 and it was decommissioned in 1990.

5. It led to the development of the Internet.

Explanation:

4 0
3 years ago
The user cannot use a computer system without.................... software<br><br>​
zheka24 [161]

Answer:

the user cannot use a computer system without hardware and software

4 0
3 years ago
Read 2 more answers
URLs are the global ______ of resources on the Internet.
adell [148]
I believe the answer might be addresses 
 <span />
4 0
3 years ago
Read 2 more answers
I need help with this!!! Are headphones, radios, dishwashers, and remote controls considered Computers? Do any of them store dat
Bogdan [553]

Answer:

Yes, these things can be considered a computer. And they can also store and process data.

Explanation:

Headphones, radios, dishwashers, and remote controls are all computers because they all have some sort of logic board inside the device to control what it does. Example, a dishwasher has internal components that it uses to keep track of how long the wash/rinse cycle have lasted and how long they are supposed to last.

I hope that helps!

7 0
2 years ago
Other questions:
  • When you were configuring Encrypting File System (EFS) in the lab, a __________ on the Documents folder in the File Explorer ind
    5·1 answer
  • What can you do to stop a computer from repeatedly restarting in a continuous loop?
    13·1 answer
  • python If the checksum is 10, the last digit is denoted as X according to the ISBN-10 convention. Write a program that prompts t
    10·1 answer
  • Which of the following could be defined as a general-purpose computing device that enables workers to create, manage, store, sea
    12·1 answer
  • Develop a Matlab program that allows you to plot the entropy of a source with variable output probabilities. We wish to observe
    8·1 answer
  • Does functionality provided by the app play an important role in a decision to
    13·1 answer
  • What do you call the physical, touchable, materials parts of a computer system?
    7·1 answer
  • How we know that how many domain exist in window server 2012?
    14·1 answer
  • Katy and her associates are approached by an aged tai chi expert to create a website for him. From her participation in an onlin
    9·1 answer
  • Can find error , suppose to print what season it is and if fails : Traceback (most recent call last):
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!