generate functionWed, 01 Mar 2023

There is a one-dimensional list with a length of 10 elements, consisting of zeros: p = [0] * 10 At each iteration of the loop, the user enters an integer - the index of the list element p, by which the value 1 is written, if it is not already there. If 1 is already set, then do not change the list and ask the user for the next number again. It is necessary to arrange five units in a list like this. (After that, the cycle is interrupted). Implement the program with a while loop and use a continue statement when 1 cannot be added to the list. Display the result on the screen as a sequence of numbers separated by a space.

p = [0] * 10 count = 0 while count < 5: i = int(input()) if p[i] == 1: continue p[i] = 1 count += 1 print(*p)

Questions about programming?Chat with your personal AI assistant