Write a program named p3.py that starts with an empty list and then asks the user for a positive integer n. Then your program must generate n random integers in the range [1-10] (inclusive) and store them in the list. Your program must then ask the user repeatedly to enter a number and a string to replace all occurrences of that number with the string (e.g., replace 1’s with "hello", 2’s with “hi”) and count the number of times a particular number was replaced by the string. Hint: use a for (counter controlled) loop inside a while (event-controlled) loop Sample output: n >> 12 List: [1, 3, 3, 9, 5, 7, 8, 2, 10, 8, 4, 1] number to change ['q' to quit]>> 1 with string >> hello List: ['hello', 3, 3, 9, 5, 7, 8, 2, 10, 8, 4, 'hello'] The number 1 was replaced 2 times in total number to change ['q' to quit]>> 8 with string >> hi List: ['hello', 3, 3, 9, 5, 7, 'hi', 2, 10, 'hi', 4, 'hello'] The number 8 was replaced 2 times in total number to change ['q' to quit]>> q
Write a program named p3.py that starts with an empty list and then asks the user for a positive integer n. Then your program must generate n random integers in the range [1-10] (inclusive) and store them in the list. Your program must then ask the user repeatedly to enter a number and a string to replace all occurrences of that number with the string (e.g., replace 1’s with "hello", 2’s with “hi”) and count the number of times a particular number was replaced by the string.
Hint: use a for (counter controlled) loop inside a while (event-controlled) loop
Sample output: n >> 12
List: [1, 3, 3, 9, 5, 7, 8, 2, 10, 8, 4, 1] number to change ['q' to quit]>> 1 with string >> hello
List: ['hello', 3, 3, 9, 5, 7, 8, 2, 10, 8, 4, 'hello']
The number 1 was replaced 2 times in total
number to change ['q' to quit]>> 8 with string >> hi
List: ['hello', 3, 3, 9, 5, 7, 'hi', 2, 10, 'hi', 4, 'hello']
The number 8 was replaced 2 times in total
number to change ['q' to quit]>> q
Step by step
Solved in 2 steps with 1 images