Problem 1 (Working with a list) Write a program named p1.py 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.

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
icon
Concept explainers
Question
100%
I noticed I am always unable to see the question when it's being send on a blank sheet of white paper because the paper is totally blank so please for precautions reasons can I have the photo of the answered question together with the paper solution thanks. In python please
Problem 1 (Working with a list)
Write a program named p1.py 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.
Print
A
Transcribed Image Text:Problem 1 (Working with a list) Write a program named p1.py 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. Print A
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]>>
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
D--LI---A
H
Print
L-1:4
Detaile
PDF
Transcribed Image Text: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]>> 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 D--LI---A H Print L-1:4 Detaile PDF
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Types of Linked List
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
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