I've been trying to figure this out for some time now, and I still can't seem to get it! I am trying to return and print the correct number of rows and columns that a user enters (when a user enters greater than or equal to 5) and when the user doesn't enter, to prompt the input statement again.
Here is my code so far:
#CONSTANTS
CON_NUM = int(5)
def correctInteger(row):
#get valid row number:
while row < CON_NUM:
row = int(input("Please enter a number bigger than or equal to 5: "))
if row >= CON_NUM:
return(row)
if row >= CON_NUM:
return(row)
def correctNum(cols):
#get valid column number:
while cols < CON_NUM:
cols = int(input("Enter a number bigger than / equal to 5: "))
if cols >= CON_NUM:
return(cols)
if cols >= CON_NUM:
return(cols)
def main():
#ask for number of rows:
print("Choose the number of rows:")
rows = int(input("Please enter a number bigger/ equal to 5: "))
#ask for columns:
print("Please choose the number of columns:")
columns = int(input("Please enter a number bigger/ equal to 5: "))
validRow = correctInteger(rows)
validColumn = correctNum(columns)
print(validRow)
print(validColumn)
main()
Here is the output this code makes:
Please choose the number of rows:
Please enter a number bigger/equal to 5: 3
Please choose the number of columns:
Please enter a number bigger/equal to 5: 5
Please enter a number bigger/equal to 5: 6
6
5
The output is very strange and I dont know how to fix it! I don't know why the while loop for the number of rows isn't working and it is only printing the columns.
Output that I am trying to get might look something like:
Please choose the number of rows:
Please enter a number bigger/equal to 5: 4
Please enter a number bigger/equal to 5: 5
Please choose the number of columns:
Please enter a number bigger/equal to 5: 3
Please enter a number bigger/equal to 5: 7
5
7
(top number being rows and bottom being columns)
I know this is really long but I hope I'm making sense! Thank you for your time!