Python Forum
Nothing happens - its a simple multiplication table!
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Nothing happens - its a simple multiplication table!
#1
def create_multiplcation_table(width, height):
	output = ""
	num_chars = len(str(width*height)) + 1
    
	for a in range(1, height+1):
		for b in range(1, width+1):
			product = a * b
                        
			product_str = str(product)
			product_str = product_str.rjust(num_chars, " ")
			output += product_str + " "
		output += "\n\n"
					
	return ouput

def process_input(raw_input):
	try:
		value = int(raw_input)
	except ValueError:
		raise ValueError("%s is not an integer" % raw_input)
			
	if value <= 0:
		raise ValueError("All dimensions must be greater than zero.")
		
	return value

def get_user_input():
	values = []
	for prompt in ('Width', 'Height'):
		raw_input = input(prompt + ": ")
		processed_input = process_input(raw_input)
		values.append(processed_input)

	return values

def main():
	success = False
	try:
		width, height = get_user_input()
		success = True
	except Exception as e:
		print(e)
	except KeyboardInterrupt:
		print("\nGoodbye.")
		
	if success:
		ouput = create_multiplcation_table(width, height)
		print('\n\n' + output)

if __name__ == '__name__':
	main()
I run this and absolutely nothing happens. This is a video tutorial. I've gone over the code and compared it with the video and I don't see a difference.

Any help will be most appreciated!

Thanks!

Tonya Wall
Reply


Messages In This Thread
Nothing happens - its a simple multiplication table! - by tjnichols - Mar-28-2018, 09:05 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Multiplication Table code alexsendlegames100 3 2,277 Jun-06-2022, 09:45 AM
Last Post: Gribouillis
  Try to solve GTG multiplication table problem. Frankduc 6 3,271 Jan-18-2022, 08:26 PM
Last Post: Frankduc
  Need help with my Python code (Multiplication) NeedHelpPython 2 2,394 Oct-04-2021, 12:09 PM
Last Post: Pedroski55
  List conversion and multiplication johnkyp 5 4,172 Jan-02-2020, 08:20 AM
Last Post: perfringo
  Matrix Multiplication Issue VIJENDRA 1 2,398 Dec-19-2019, 06:16 PM
Last Post: Gribouillis
  Multiplication between a list and a variable doug2019 2 2,808 Oct-08-2019, 04:10 AM
Last Post: doug2019
  Multiplication Table number margins CJ707 4 3,372 Sep-18-2019, 02:16 PM
Last Post: CJ707
  multiplication by successive addition Zebrol 1 4,383 Sep-14-2019, 05:37 PM
Last Post: ichabod801
  Tracing a multiplication table w/ Python trace() NationalRex22 0 2,187 Jun-11-2019, 03:31 AM
Last Post: NationalRex22
  float multiplication - unexpected output inesk 3 4,163 Dec-11-2018, 10:59 AM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020