Write a pyhton program that starts with an empty list. Your program must ask the user for a positive integer n, generate n random integers in the range [1-10] (inclusive), store them in that list, and print it. Your program then must repeatedly ask the user to enter a number and a string to replace all occurrences of that number in the list with that string (e.g., replace all 1’s with "hello", all 8’s with “hi”, etc.). At every iteration, print the updated list and the number of times a number was replaced. Your program stops when the user enters ‘q’. Input validation is optional. Hint: use a for (counter controlled) loop inside a while (event-controlled) loop. Sample output: n >> 13 List: [1, 3, 3, 9, 5, 7, 8, 2, 10, 8, 4, 1, 1] Enter a number to change ['q' to quit]>> 1 with string >> hello List: ['hello', 3, 3, 9, 5, 7, 8, 2, 10, 8, 4, 'hello', 'hello'] The number 1 was replaced 3 times Enter a number to change ['q' to quit]>> 8 with string >> hi List: ['hello', 3, 3, 9, 5, 7, 'hi', 2, 10, 'hi', 4, 'hello', 'hello'] The number 8 was replaced 2 times Enter a number to change ['q' to quit]>> q

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Write a pyhton program that starts with an empty list. Your program must ask the
user for a positive integer n, generate n random integers in the range [1-10] (inclusive),
store them in that list, and print it.
Your program then must repeatedly ask the user to enter a number and a string to replace
all occurrences of that number in the list with that string (e.g., replace all 1’s with "hello",
all 8’s with “hi”, etc.). At every iteration, print the updated list and the number of times a
number was replaced. Your program stops when the user enters ‘q’. Input validation is
optional.


Hint: use a for (counter controlled) loop inside a while (event-controlled) loop.


Sample output:
n >> 13
List: [1, 3, 3, 9, 5, 7, 8, 2, 10, 8, 4, 1, 1]
Enter a number to change ['q' to quit]>> 1
with string >> hello
List: ['hello', 3, 3, 9, 5, 7, 8, 2, 10, 8, 4, 'hello', 'hello']
The number 1 was replaced 3 times
Enter a number to change ['q' to quit]>> 8
with string >> hi
List: ['hello', 3, 3, 9, 5, 7, 'hi', 2, 10, 'hi', 4, 'hello', 'hello']
The number 8 was replaced 2 times
Enter a number to change ['q' to quit]>> q

Expert Solution
steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Knowledge Booster
Time complexity
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education