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
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
According to the information given:-
We have to follow the instruction in order to get desired outcome.
Step by step
Solved in 3 steps with 2 images