create a 2D array filled with integers that met the following requirements: -A random…
- User
create a 2D array filled with integers that met the following requirements:
-A random number between 1 and a maximum number inclusive -Divisible by 10 -Not divisible by 100
Assistant
Here is a Python code to create a 2D array filled with random integers between 1 and 100, inclusive, that are divisible by 10 but not 100:
import random max_num = 100 rows = 5 cols = 5 arr = [[0] * cols for _ in range(rows)] for i in range(rows): for j in range(cols): num = random.randint(1, max_num) while num % 10 != 0 or num % 100 == 0: num = random.randint(1, max_num) arr[i][j] = num print(arr)This code:
- Initializes an empty 2D array of size rows x cols with all elements as 0
- Loops through each element of the array
- Generates a random number between 1-100
- Checks if it is divisible by 10 but not 100 using modulo operators
- If not, generates another random number
- Once a valid number is found, it is assigned to the array element
- Prints the final 2D array
Let me know if you have any other questions!
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.