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
lyudmila [28]
2 years ago
8

Design the program in the following way:

Computers and Technology
1 answer:
natali 33 [55]2 years ago
5 0

Answer:

d = {}

while True:

   name = input("Enter the name of the boat (Press Enter or q to stop): ")

   if name == "" or name == "q":

       break

   time = int(input("Enter the time (in seconds): "))

   d[name] = time

winner_name = min(d, key=d.get)

winner_time = min(d.values())

average_time = sum(d.values()) / len(d.values())

slowest_boat = max(d, key=d.get)

slowest_time = max(d.values())

print(f"Winner name: {winner_name} and its time: {winner_time}")

print(f"Average time: {average_time}")

print(f"Slowest boat: {slowest_boat} and its time: {slowest_time}")

Explanation:

*The code is in Python.

Create an empty map(dictionary) to hold the values

Create a while loop. Inside the loop:

Ask the user to enter the name of the boat. Check if the user presses Enter or q, using if and break

Ask the user to enter the time

Insert these values as key-value pair to the map

When the loop is done:

Find the winner_name, the min() function finds the minimum value in a list. In this case, the key=d.get creates a list of the values in the map. The min(d, key=d.get) returns the key of the minimum value

Find the winner_time, min(d.values()) returns the minimum time in our map

Find the average time, the sum() function, returns the sum of the values in a list. In this case, sums all the values in the map. The len() function finds the count of the values. If we divide the sum of times entered by the count of the times entered, we get the average time

Find the slowest_time, the max() function returns the max of the value in a list. In this case, the maximum value is the slowest time

Print the results

You might be interested in
The main trade-off that all investors must consider is
Talja [164]
<span>The main trade-off that all investors must consider is Risk vs Return
In the end, all the techniques that implemented in investing process is aimed for nothing other than profit.
Current market trend dictates that potential return tend to be higher the riskier the investment is and vice versa.
</span>
3 0
3 years ago
Read 2 more answers
Lottery Number Generator Design a program that generates a 7-digit lottery number. The program should have an Integer array with
Nikolay [14]

Answer:

/******************************************************************************

                             Online C++ Compiler.

              Code, Compile, Run and Debug C++ program online.

Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>

#include <string>

#include <sstream>

using namespace std;

bool equal(int sys[],int user[])

{

    for (int i=0;i<7;i++)

{

 if(sys[i]!=user[i]){

     return false;

 }

}

return true;

}

int main()

{

int sys[7];

int user[7];

int min=0

;int max=9;

string userinput;

while(0==0){

for (int i=0;i<7;i++)

{

    sys[i]=rand() % (max - min + 1) + min;

}

cout <<endl;

   cout<<"enter numbers"<<endl;

for (int i=0;i<7;i++)

{

 getline (cin,userinput);

    if(userinput=="x"){

        return 0;

    }

    else{

 stringstream(userinput) >> user[i];

   

    }

}

     cout<<"User number"<<endl;

for (int i=0;i<7;i++)

{

    cout << user[i];

}

    cout<<"system number"<<endl;

for (int i=0;i<7;i++)

{

    cout << sys[i];

}

if(equal(sys,user))

{

   cout<<"You won !"<<endl;

}else {

       cout<<"Try again :("<<endl;

}

}

   return 0;

}

Explanation:

Using c++ rand function generate a random number between 0-9.

Formula for random number is rand (max-min +1)+min.

Run this in a loop for 7 time and store each number to an array index in sys array which is for system generated number.

now using string take input from user and check if input is x close program else use stringstream to parse input string to int and store it in user array. Stringstream is a cpp header file used for parsing and handling of strin g inputs. Run this program in loop for 7 times.

Now create a function of type boolean denoted by "bool". This will take both arr as parameter and check if both are equal or not. It compares eac index of user array against each index of sys array and if both values are not equal returns false.

5 0
3 years ago
A = 250; B = 325. which of the following statements is true? A ==B A&gt;B A =B
Feliz [49]

Answer:

It should be A<B

Explanation:

250 is less than 325

5 0
2 years ago
Which of the following is an example of how the respiratory system interacts with the circulatory system to excrete waste?
Varvara68 [4.7K]

Answer:

The veins carry oxygen depleted blood away from body parts,  hence the color blue.

Explanation:

5 0
2 years ago
2. The password dilemma refers to the fact that: A. Passwords that are easy for users to remember are also easy for attackers to
Sholpan [36]

Answer:

Option A.

Explanation:

5 0
2 years ago
Other questions:
  • A person planning to file for bankruptcy must receive credit counseling within two years before filing the petition.
    7·1 answer
  • If you have a list of words that you wish me to make into a bulleted list, you must first highlig or ______ The words with the c
    13·1 answer
  • Janelle went to update the last name for one of her group contacts. She double-clicked on the contact, changed the last name, an
    12·2 answers
  • How do I answer a question on Brainly.com without an “oops” notification?
    7·2 answers
  • To resize columns in a subform, press and hold or right-click the subform in the navigation pane, and tap or click ____ on the s
    12·1 answer
  • Run the browser checker to see that the computer you are using now is set up for WileyPLUS. Which of the following browser funct
    15·1 answer
  • which of the following statements about matter is true a.matter is anything that occupies space and possesses mass b.matter can
    5·2 answers
  • Write a program which increments from 0 to 20 and display results in Decimal on the console 2-b) Modify above program to increme
    6·1 answer
  • Write a method called classAttendence() that creates a 10-by-10 two-dimensional array and asks for user input to populate it wit
    14·1 answer
  • When machining rotors, what is the reason for setting the indexing collars to zero?
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!