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
A network administrator has been tasked with configuring access to the Internet for about 50 computers. The administrator has be
scoundrel [369]

Answer:

Proxy Server.

Explanation:

An administrator was given the responsibility of customizing Internet connection for around the numbers of computer systems. He stated the admin that those Internet connections need to go through a system connected to the internet because otherwise inbound and outbound traffic can still be examined but only that systems should have a Web address identified.

So, the admin configured Proxy Server because only certain systems have been identified the following address to the internet.

3 0
3 years ago
What is outlook used for?
Arte-miy333 [17]
Outlook is used for mainly emails. It also keeps track of your calendar, has contact and tasks.
4 0
2 years ago
Read 2 more answers
What is the Moore's law
Nadya [2.5K]

Answer:

Hi, in the law of Moore we can express aproxitmaly for each <em>two years</em> is duplicated the number of transitors in a microprocessor.

Explanation:

In around 26 years the number of transitors has increased about 3200 times, a transitor is a way to regulate the current voltage flow and can be act like a <em>switch</em> for an electronic signal.

I hope it's help you.

4 0
3 years ago
Write some positive and negative impacts of computer in our daily life​
8090 [49]
Positive impacts are
1. Communicating with people
2. Daily update of what going on in the world
3. learn new things
Negative impacts are
1. Viruses
2. Private information shared
3. Less face to face conversations
3 0
2 years ago
Daphne has determined that she has malware on her linux machine. She prefers to only use open-source software. Which anti-malwar
Llana [10]

Answer:

ClamAV is the open source antivirus you can in your Linux machine.

5 0
2 years ago
Other questions:
  • Sarah is creating and formatting a newsletter for her school. Which page layout rules should she consider when doing this?
    13·2 answers
  • epic poem - long narrative poem about heroic deeds about pharrell williams of the happy song please help i need the right answer
    11·1 answer
  • To find out how much ram is installed on a machine, in windows go to the user: a power ______ is a part inside a computer case t
    6·1 answer
  • For a new version of processor, suppose the capacitive load remains, how much more energy will the processor consume if we incre
    12·1 answer
  • A style sheet consists of CSS ______________________ that specify the layout and format properties to apply to an element. *
    13·1 answer
  • Please answer that and i'll gave you branlliest
    15·1 answer
  • Take two String inputs of the same length and merge these by taking one character from each String (starting with the first ente
    8·2 answers
  • If i keep giving out brainlyest will i get banned again?
    12·2 answers
  • Which of the following statement is correct ? A . potential difference is measured by ammeter . B . The unit of potential differ
    9·1 answer
  • How do I do this??? (Im in 9th)
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!