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
In “Plugged In,” the author’s purpose is to persuade. Which of the following quotes from the text shows that the author’s purpos
lisabon 2012 [21]

The quote from the text that shows that the author’s purpose is to persuade is D. Critics say that kids stare at computers and TVs all day and do not get enough exercise. The facts stand in counterpoint to this belief.

An argumentative writing prompt is written in order to convince the readers about a particular issue.

According to the author, the fact that children are involved in watching movies, playing games, listening to music, etc doesn't mean that they can't still be productive.

There are some critics that believe that kids stare at computers and TVs all day and do not get enough exercise. This was countered by the author who stated that kids can still engage in exercises or do other productive things.

Read related link on:

brainly.com/question/24861556

3 0
3 years ago
What effect does social media have on teens?
myrzilka [38]

Answer:

manipulation is the answer

3 0
3 years ago
Read 2 more answers
Roark has just joined a company and in his role as a lead analyst, he will be responsible for determining which systems developm
hram777 [196]

Answer:

Agile/adaptive methods.

Explanation:

The user has just decided to join a firm and will also be accountable to determine whether that system development technique that group uses to establish the latest software for a significant medical distributor to his position as just a lead analyst.

After that, he consumes a week for the purpose to understand his group members for reason to know their strengths and weakness and how would they work under pressure.

So, the following method is required for him to understand about the disadvantages of each of them.

4 0
3 years ago
Wanna play pubg<br><br><br>ill send u my id​
Nikitich [7]
My sister would what’s your id
6 0
3 years ago
Read 2 more answers
The part of the eye thats similar to the film of a camera is the
Lapatulllka [165]
The retina is the part pf the eye that is similar to the film of a camera. It is a thin layer of cells that is located at the back of the eyeball. This part contains photoreceptor cells which respond to light where the neural signals received undergoes complex processing by other neurons in the retina.
3 0
3 years ago
Other questions:
  • Add the following functions to the code:
    9·1 answer
  • What are the pros and cons of the internet’s ability to access information
    8·2 answers
  • Suppose barriers to entry exist in the telecommunications industry. This best describes a _____ market.
    12·1 answer
  • Choose all items that represent characteristics of an HTML element. used to include additional information in an attribute consi
    15·1 answer
  • Consider an unpipelined or single-stage processor design like the one discussed in slide 6 of lecture 17. At the start of a cycl
    10·1 answer
  • Two employees were very different in terms of​ age, gender, and other demographic data but they shared a common love of dogs and
    8·1 answer
  • Expain the application areas of ICT in education sector and E-commerce​
    12·1 answer
  • Which text features does this section contain? Check all that apply.
    15·1 answer
  • What is the term used to describe the basic unit of data passed from one computer to another
    14·1 answer
  • Someone put malware on your computer that records all of your keystrokes. what aspect of security was primarily attacked? choose
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!