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.

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter17: Linked Lists
Section: Chapter Questions
Problem 16PE
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
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning