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
The programmer must initialize variables when they are declared
lorasvet [3.4K]

Answer: When you declare a variable, you should also initialize it. Two types of variable initialization exist: explicit and implicit. Variables are explicitly initialized if they are assigned a value in the declaration statement. Implicit initialization occurs when variables are assigned a value during processing.

Explanation:

For example, in JavaScript

var PaintAmount = 50; -declare and initialize  

function setup() {

   creatCanvas(200, 200);

}  

function draw() {

   ellipse(PaintAmount, PaintAmount) -use the variable PaintAmount

}

or rather in Java,

package random;

public class something() {

Public static void Main(String []args) {

        string name;  // this is declaring the variable with the example type  

     

       string name = new string; //this initializes the declared variable

}

}

6 0
3 years ago
By default, the pfsense firewall allows unrestricted outbound access from the lan interface. true or false?
Sav [38]

The statement "By default, the pfSense firewall allows unrestricted outbound access from the lan interface" is true.

pfSense is free and open source firewall and router that can be installed on a physical computer or a virtual machine. Teh goal is to make the machine a dedicated firewall/router for a network.

 It features unified threat management, load balancing, multi WAN etc.


8 0
4 years ago
Read 2 more answers
Which feature is needed to make enterprise application migrate to private cloud ?
den301095 [7]

The answer is C: Enablement of application as SaaS.

A cloud can provide IT infrastructure network services like storage and servers. Once an application has been identified as a potential candidate for cloud migration, it is important to consider what type of cloud environment; PaaS, SaaS, or IaaS. In this case, SaaS will be considered. SaaS host business application and makes them available to clients online. It removes the need for enterprises to run applications on their own.

8 0
3 years ago
Read 2 more answers
In this exercise, you will be given a phrase that includes the word “meat”. Replace that word with the word “fruit” and return t
Aleks [24]

Answer:

Answer is in the provided screenshot!

Explanation:

This answer is actually a simplified version of another question I've answered for you here: brainly.com/question/15538849

If you need any more explanation on how this algorithm works, please ask me!

8 0
3 years ago
Now plz<br>draw the main memory​
Sophie [7]

Answer: Here is my answer- I hope it helps! Btw I did search this up but I change some words so I don't get in trouble again ; - ;

Explanation: A unit of measurement is a definite importance of an amount, defined and adopted by convention or by law, that is used as a standard for measurement of the same kind of amount. Any other amount of that kind can be expressed as a multiple of the unit of measurement. For example, a length is a physical amount.

3 0
3 years ago
Other questions:
  • A group of eight bits is called a _______. a. numeric data b. byte c. megabit d. binary
    5·1 answer
  • Angela's ready to get started with her first Smart Display campaign, but her account isn't yet eligible due to not having enough
    11·1 answer
  • An IT company revises its process parameters in response to complaints from vendors that products were not ready on time. This w
    15·1 answer
  • Which one of the following will not be considered as a microcomputer?
    12·2 answers
  • The problem with the media giving equal air time to those who are __________ about the effects of media violence on violent beha
    9·1 answer
  • At the Transport layer of the OSI, what is used to find and communicate with a particular application running on a host?
    7·1 answer
  • To quit, a user types 'q'. To continue, a user types any other key. Which expression evaluates to true if a user should continue
    7·1 answer
  • Please help!!! I am very confused about this question!
    10·1 answer
  • If the transmitting device would like for the receiving device to push currently buffered data to the application on the receivi
    15·1 answer
  • What is a query? State it's uses.​
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!