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
All of the following items could be too expensive for someone with only a high school degree to afford except
Papessa [141]
This sounds like a multiple choice answer can I have 4 choices to pick?
7 0
3 years ago
A start-up employs interns. The following details of interns are stored
Rufina [12.5K]

Answer: See below.

class Intern:

   def __init__(self):

       self.first_name = input("Enter first name: ")

       self.last_name = input("Enter last name: ")

       self.address = input("Enter address: ")

       self.mobile_number = input("Enter mobile number: ")

       self.e_mail = input("Enter e-mail: ")

   def getdata(self):

       print("First name: ", self.first_name)

       print("Last name: ", self.last_name)

       print("Address: ", self.address)

       print("Mobile number: ", self.mobile_number)

       print("E-mail: ", self.e_mail)

   def putdata(self):

       print("First name: ", self.first_name)

       print("Last name: ", self.last_name)

       print("Address: ", self.address)

       print("Mobile number: ", self.mobile_number)

       print("E-mail: ", self.e_mail)

Explanation:

7 0
2 years ago
Identify the type of error.<br> print "hello"<br><br> num = 5 / 0
horrorfan [7]

Answer:

Syntax error

Explanation:

This is a type of error that occurs when there is a problem with the code that makes it unable to compile and execute.

For example, making a conditional statement without using the correct parameters will result in a syntax error.

4 0
3 years ago
Read 2 more answers
Which of the following is an example of a tracking
Vikentia [17]
22222222222222222222
5 0
3 years ago
Read 2 more answers
Columns are identified by numbers (1,2,3,4,5....) and Rows are identified by letters (A,B,C,D,E.....) True False
igomit [66]
The answer would be true. Hope this helps you
8 0
3 years ago
Other questions:
  • In normal view, powerpoint's ________ contains buttons such as notes, comments, and view.
    14·1 answer
  • Universal Containers offers a variety of products that are comparable to products from other companies. Sales representatives re
    14·1 answer
  • The main workplace of a Windows computer is called the
    14·1 answer
  • Greyer Corp, manufactures surgical instruments. Systems Medico Inc. enters into a contractual arrangement with Greyer that allow
    7·1 answer
  • (1) Prompt the user to enter four numbers, each corresponding to a person's weight in pounds. Store all weights in a list. Outpu
    7·1 answer
  • If you receive an email message you suspect is spam, what should you do?
    11·1 answer
  • Which option is the primary means of communication for coauthors working on PowerPoint presentations?
    10·1 answer
  • Question:
    14·1 answer
  • In query design view you can add .............. to limit the number of records shown in the resulting datasheet
    13·1 answer
  • A _____ model is one that is automatically adjusted based on changing relationships among variables.
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!