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
natta225 [31]
3 years ago
9

Write a program that asks for 'name' from the user and then asks for a number and stores the two in a dictionary (called 'the_di

ct') as key-value pair. The program then asks if the user wants to enter more data (More data (y/n)? ) and depending on user choice, either asks for another name-number pair or exits and stores the dictionary key, values in a list of tuples and prints the list. Note: Ignore the case where the name is already in the dictionary. Example: Name: pranshu Number: 517-244-2426 More data (y/n)? y Name: rich
Computers and Technology
1 answer:
AleksAgata [21]3 years ago
6 0

Answer:

#Declare the variables.

the_dict = {}

dictlist = []

#Begin the while loop.

while True:

   #Prompt the user to enter the name

   #and the number.

   input_name = input("Name: ")

   input_number = input("Number: ")

   

   #Ask the user to continue or stop

   #the program.

   input_choice = input('More data (y/n)? ')

   the_dict[input_name] = input_number

   

   #Check the input.

   if input_choice == 'n':

       break

#If the user want to continue

#then append in the list.

for key, value in the_dict.items():

   

   #Store the values in dictionary.

   temp_val = (key,value)

   dictlist.append(temp_val)

   

#Sort the list.

print(sorted(dictlist))

You might be interested in
____ is a philosophy and a software and system development methodology that focuses on the development, use, and reuse of small,
LiRa [457]

Answer:

d.) Service-Oriented Architecture

Explanation:

Because its definition matches

4 0
3 years ago
DO NOT JOIN ANY Z O O M MEETINGS FROM THIS PERSON! IS A TRAP Please help me get them banned!!!!!
s2008m [1.1K]

Answer:

how do i help?

Explanation:

7 0
3 years ago
Read 2 more answers
Two devices that may be used for creating,storing,and transmitting documents input devices
castortr0y [4]

Answer:

electronic notebook or a pc?

Explanation:

sorry if its wrong of doesnt help

6 0
3 years ago
Two cars A and B leave an intersection at the same time. Car A travels west at an average speed of x miles per hour and car B tr
drek231 [11]

Answer:

Here is the C++ program:

#include <iostream>  // to use input output functions

#include <cmath>  // to use math functions like sqrt()

#include <iomanip>  //to use setprecision method

using namespace std;   //to access objects like cin cout

int main ()  {  //start of main function

  double speedA;  //double type variable to store average speed of car A

  double speedB;  //double type variable to store average speed of car B

  int hour;  //int type variable to hold hour part of elapsed time

  int minutes;  //int type variable to hold minutes part of elapsed time

  double shortDistance;  // double type variable to store the result of shortest distance between car A and B

  double distanceA;  //stores the distance of carA

  double distanceB;  //stores the distance of carB

  double mins,hours;   //used to convert the elapsed time

cout << "Enter average speed of car A: " << endl;  //prompt user to enter the average speed of car A

cin >> speedA;   //reads the input value of average speed of car A from user

cout << "Enter average speed of car B: " << endl ;  //prompt user to enter the average speed of car B

cin >> speedB;   //reads the input value of average speed of car A from user

cout << "Enter elapsed time (in hours and minutes, separated by a space): " << endl;  //prompts user to enter elapsed time

cin>> hour >> minutes;    //reads elapsed time in hours and minutes

  mins = hour * 60;  //computes the minutes using value of hour

  hours = (minutes+mins)/60;     //computes hours using minutes and mins

distanceA = speedA * (hours);  // computes distance of car A

distanceB = speedB * (hours);   //computes distance of car B

   shortDistance =sqrt((distanceA * distanceA) + (distanceB * distanceB));   //computes shortest distance using formula √[(distanceA)² + (distanceB)²)]

cout << "The (shortest) distance between the cars is: "<<fixed<<setprecision(2)<<shortDistance;

//display the resultant value of shortDistance up to 2 decimal places

Explanation:

I will explain the program with an examples:

Let us suppose that the average speeds of cars are:

speedA = 70

speedB = 55

Elapsed time in hours and minutes:

hour = 2

minutes = 30

After taking these input values the program control moves to the statement:

mins = hour * 60;  

This becomes

mins = 2 * 60

mins = 120

Next

hours = (minutes+mins)/60;

hours = (30 + 120) / 60

         = 150/60

hours = 2.5

Now the next two statements compute distance of the cars:

distanceA = speedA * (hours);  

this becomes

distanceA = 70 * (2.5)

distanceA = 175

distanceB = speedB * (hours);

distanceB = 55 * (2.5)

distanceB = 137.5

Next the shortest distance between car A and car B is computed:

shortDistance = sqrt((distanceA * distanceA) + (distanceB * distanceB));

shortDistance = sqrt((175 * 175) + (137.5 * 137.5))

                        = sqrt(30625 + 18906.25)

                        = sqrt(49531.25)

                        =  222.556173

shortDistance =  222.56

 

Hence the output is:

The (shortest) distance between the cars is: 222.56        

3 0
3 years ago
How do you enlarge your screen if there is no control panel? Need desperate help!
igor_vitrenko [27]
You hit ctrl than the plus/equal sign Hope that helped! 
4 0
3 years ago
Other questions:
  • What is a independent variable
    11·1 answer
  • You coded the following class: public class N extends String, Integer { }When you compile, you get the following message:N.java:
    9·1 answer
  • Which do switches create?<br> Networks<br> Wireless access points<br> Routes<br> Collision domains
    13·1 answer
  • Bruh my sister does bot understand what this means
    6·1 answer
  • How do you change the order of the slides in your presentation in the slide pane 
    15·2 answers
  • Compress<br> 00eb:0000:0000:0000:d8c1:0946:0272:879<br> IPV6 Address
    9·1 answer
  • He should identify his various
    6·1 answer
  • Create a set of functions that compute the mean, median, and mode of a set of
    8·2 answers
  • What tool allows you to search external competitive intelligence research?
    14·1 answer
  • What are the advantages of cloud computing over computing on premises?
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!