70.0k views
4 votes
Create a script file that asks the user to input the number of rows, number of columns, and a constant integer value (may be negative, zero or positive) and then creates the matrix.

Use a user-defined function to obtain the input. Check that the number of rows and number of columns is between 1 and 8 inclusive [1:8], and that the constant value IS an integer. Give the user another chance if they enter an illegal value, do not just shut down the program. You can either put the user function in the body of the main script file or create a separate file and submit it at the end of the exam in one of the fake questions. Check your program for these 2 cases:

2 rows, 4 columns, value of -77
2 rows, 6 columns, value of 13

User Israel
by
5.5k points

1 Answer

7 votes

Answer:

def script_input():

chances = 2

while chances > 0:

global rows

global columns

global constant

rows = int(input("Enter the number of rows: "))

columns = int(input("Enter the number of columns: "))

constant = int(input("Enter the constant: "))

if rows > 0 and rows <= 8 and columns > 0 and columns <= 8 and \

isinstance(constant, int):

chances -= 2

else:

chances -= 1

script_input()

print(f"{rows} rows, {columns} columns, value of {constant}")

Step-by-step explanation:

The python script defines a function that gets the user input of row, column and constant value variables, then the script prints out the number of rows and columns for the matrix to be created.

User Marom
by
5.9k points