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
andreyandreev [35.5K]
3 years ago
11

Create an old sample dictionary {0:10, 1:20} as follows to store numbers. Write a Python script to ask how many runs from user i

nput to add items to the old dictionary. Use a loop to append these key/value pairs to the dictionary. Print out the resulting dictionary for each run (NOT just the last run). Please find the number patterns to append key/value pairs. You cannot add the numbers manually.

Computers and Technology
1 answer:
Amiraneli [1.4K]3 years ago
8 0

Answer:

Here is the Python code:

runs=int(input("how many runs do you want to add items to dictionary? "))  #store input number of runs

d = dict()  #creates a dictionary

d = {0:10,1:20}  #old dictionary

count=0  #counts number of runs

for x in range(2,runs+2):  #loop to append key/value pairs to dictionary

   d[x]=(x*10)+10  #multiples and adds 10 to the each value

   count+=1  #adds 1 to the count at each iteration

   print("After the #",count, "run the new dictionary is: ",d) #prints the new dictionary

Explanation:

I will explain the program with an example:

The old dictionary is :

d = {0:10,1:20}  

runs = 3

count = 0

At first iteration:

x = 2

d[x]=(x*10)+10

This becomes:

d[2]=(2*10)+10

d[2]= 20 + 10

d[2]= 30

count+=1

count = 1

   print("After the #",count, "run the new dictionary is: ",d)

This statement displays the first iteration result :

After the # 1 run the new dictionary is:  {0: 10, 1: 20, 2: 30}  

At  second iteration:                                                              

x = 3

d[3]=(3*10)+10

This becomes:

d[3]=(3*10)+10

d[3]= 30 + 10

d[3]= 40

count+=1

count = 2

   print("After the #",count, "run the new dictionary is: ",d)

This statement displays the first iteration result :

After the # 2 run the new dictionary is:  {0: 10, 1: 20, 2: 30, 3: 40}      

At  third iteration:                                                              

x = 4

d[4]=(4*10)+10

This becomes:

d[4]=(4*10)+10

d[4]= 40 + 10

d[4]= 40

count+=1

count = 3

   print("After the #",count, "run the new dictionary is: ",d)

This statement displays the first iteration result :

After the # 3 run the new dictionary is:  {0: 10, 1: 20, 2: 30, 3: 40, 4: 50}    

Now the loop breaks as x = 5 necause n+2 = 3+2 = 5 limit is reached

The screenshot of program along with its output is attached.

You might be interested in
How do you answer someone's question when they have asked?
blondinia [14]

Answer:

press answer or add answer

Explanation:

8 0
3 years ago
Read 2 more answers
Can someone suggest how to manage a group when you are the group leader?​
docker41 [41]

Answer:

Learn how to effectively conduct a critical conversation about a particular topic, or topics, that allows participation by all members of your organization.

WHAT IS AN EFFECTIVE GROUP DISCUSSION?

WHY WOULD YOU LEAD A GROUP DISCUSSION?

WHEN MIGHT YOU LEAD A GROUP DISCUSSION?

HOW DO YOU LEAD A GROUP DISCUSSION?

DO'S AND DON'TS FOR DISCUSSION LEADERS

Explanation:

be true too

hehe

3 0
3 years ago
Read 2 more answers
Do anti viruses install themselves on other computers in the network
egoroff_w [7]
Not usually. Normally, an Antivirus requires a paid licence per computer. If an "Antivirus" is spreading via the network, it's a safe bet it's either a rogue Antivirus, or an infection disguised as an Antivirus.
4 0
4 years ago
It is where your cpu (processor) is installed
Fofino [41]
The motherboard (CPU SOCKET)
4 0
4 years ago
Read 2 more answers
Which two tasks are responsibilities of a network administrator?
Vesna [10]

1.Configuring network hardware like servers, routers and switches.

2.Upgrading and repairing computer networks.

3.Troubleshooting network issues.

4.Assisting network architects with the design of network models.

5. Deploying and updating software.

Explanation:

7 0
3 years ago
Other questions:
  • A friend has a CD of one of your favorite artists and has offered to let you copy it.
    8·1 answer
  • Using a loop, write a program that reads in exactly five integers and outputs the sum.
    11·1 answer
  • Which directory in the FHS stores programs and configuration information that can only be executed and modified by the root user
    10·1 answer
  • Josh wants to convey his best wishes to johnathin for a meeting schedualed later diring the day. Which business documented would
    7·1 answer
  • Consider the following high-level recursive procedure: long long int flong long int n, long long int k long long int b b k+2; if
    9·1 answer
  • What has happened (or is still happening) to make this speech occur? armageddon
    15·1 answer
  • A consumer wants to add a hard drive to their computer to store video from their camera. Which of the following would represent
    9·1 answer
  • Embedded operating systems control?
    5·1 answer
  • When a derived class method has the same name as a base class method, it is often said that the derived class method ________ th
    13·1 answer
  • Which three characteristics help identify a business opportunity? (Choose three)
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!