The following program is supposed to output numbered rows and columns (as in 1A, 1B, 1C, etc.) based on user input. If user enters 1 3, the output should be (1A 1B 1C). If the user enters 5C, the output should be (1A 1B 1C 2A 2B 2C 3A 3B 3C 4A 4B 4C 5A 5B 5C), etc.
I’m struggling with lines 9 and 10 of the code. I know that somewhere in there I need to include num_cols but so far I’m having a really hard time figuring out where it should go.
If I assign j = "A" then J becomes a string and I can’t compare it to num_cols, but if I don’t assign j = "A" then I’m not sure how to get the j to spit out alpha characters over numeric. Any help is greatly appreciated.
num_rows = int(input())
num_cols = int(input())
# Note 1: You will need to declare more variables
# Note 2: Place end=' ' at the end of your print statement to separate seats by spaces
i = 1
j = 1
while i <= num_rows:
j = "A"
while j <= "C":
print("{}{}".format(i, j), end= " ")
j = chr(ord(j) + 1)
i += 1
print()
Please cut/paste the full error text inline. Those of us on email do not
see screenshots, and even if we visit the forum we can’t cut/paste from
the text in a screenshot (leaving aside whether any vision impairment
might make the font/colour in the screenshot hard to work with).
Thanks. You can use nested for loops controlled by the user’s input.
Here is a suggested header for the outer loop:
for i in range(num_rows):
Are you familiar with the documentation on the official Python web site? See Built-in Functions. The following may be particularly helpful for this project.
num_rows = int(input(" Ryan O’Hagan please enter your number \n"))
i = 1
j = ()
while i <= num_rows:
j = “A”
while j <= “C”:
print("{}{}".format(i, j), end= " ")
j = chr(ord(j) + 1)
i += 1
print()
@Rohagan4#Check this out Ryan. You declared a global variable j with a value and also declared local variable j with different value. “instead of making j = 1 in global var, do it j =()” Also I suppose there is no need for num_cols… Please Run and see if that is how you want it
It is a good idea to format Python code for posting. Then it will be properly indented, and therefore easy for other users to copy and paste for testing. Please see About the Users category for advice on how to do this.