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
List of steps to apply bold and italic formatting to a word​
ch4aika [34]
To make text bold, select and highlight the text first. Then hold down Ctrl (the control key) on the keyboard and press B on the keyboard. To make text italic, select and highlight the text first. Then hold down Ctrl (the control key) on the keyboard and then press the I on the keyboard
5 0
3 years ago
Read 2 more answers
Summarize the five stages of cultural shock
Anton [14]
1. Honeymoon stage
2. Distress and anxiety
3. Adjustment
4. Adaption
5. Re-entry shock
8 0
3 years ago
Read 2 more answers
a client has requested adjustments to the arrangement and placement of elements on an image. what does the client want changed?
qaws [65]

Considering the situation described above, the client wants the <u>image's recipe to be changed.</u>

<h3>What is the Image Recipe?</h3>

Image Recipes are characteristics of an image or picture. It includes features like shape, size, form, pattern, line, shadow, tone, color, contrast, positive space and negative space, etc.

Given that the client needs adjustments to the arrangement and placement of elements on an image, this is a request for a change in the image recipe.

Hence, in this case, it is concluded that the correct answer is "<u>the client wants the recipe of the image changed."</u>

Learn more about the Image Recipe here: brainly.com/question/1605430

6 0
2 years ago
Which of the following is another term for a subfolder?
LenKa [72]
Subdirectory

Have a great day! c:
5 0
2 years ago
It converts Assembly Language into machine language?​
docker41 [41]

Answer:

An assembler.

Explanation:

Input is (as with any programming language) files with lists of instructions (typically assembler mnemonics), output is a binary format representing these instructions in machine language.

6 0
2 years ago
Other questions:
  • Dial-up connections can be made over a(n) ____ line or phone line. isdn dsl ipx tcp/ip
    12·1 answer
  • The salesperson in a cell phone store is telling me that the phone I'm considering has 8GB of memory, which means I can save 10,
    13·1 answer
  • What natural boundary separated british territory from louisiana?
    7·1 answer
  • Convert to octal. Convert to hexadecimal. Then convert both of your answers todecimal, and verify that they are the same.(a) 111
    12·1 answer
  • A server would experience a __________ attack when a hacker compromises it to acquire information from it from a remote location
    13·1 answer
  • To what would you compare the transport layer?
    14·1 answer
  • What functions do these WLAN applications and tools perform on WLANs: airmonng, airodump-ng, aircrack-ng, and aireplay-ng
    10·1 answer
  • Most network behavior analysis system sensors can be deployed in __________ mode only, using the same connection methods as netw
    8·1 answer
  • You were just hired as an IT Specialist for Smalltown School District. Your first assignment is to review a problem area&amp; in
    11·1 answer
  • quizlet ann is a security professional for a midsize business and typically handles log analysis and security monitoring tasks f
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!