Python Forum
Nothing happens - its a simple multiplication table! - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Nothing happens - its a simple multiplication table! (/thread-9240.html)

Pages: 1 2


Nothing happens - its a simple multiplication table! - tjnichols - Mar-28-2018

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


RE: Nothing happens - its a simple multiplication table! - Larz60+ - Mar-28-2018

if __name__ == '__name__':
well it will never be, use:
if __name__ == '__main__':



RE: Nothing happens - its a simple multiplication table! - tjnichols - Mar-28-2018

Thanks for getting back with me - I don't see a difference? My blindness is a definite possibility! Ok - I'm not literally but I seriously don't see it.


RE: Nothing happens - its a simple multiplication table! - Larz60+ - Mar-29-2018

Look again (part in quotation marks)!


RE: Nothing happens - its a simple multiplication table! - tjnichols - Mar-30-2018

def create_multiplication_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 output

    
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:
        output = create_multiplication_table(width, height)
        print('\n\n' + output)
    
if __name__ == '__main__':
    main()
Alright - changes made - it still doesn't work.

I truly don't mean to come off as a 'ditz'. After staring at this for so long trying to find the problem, I can't see the forest for the trees. I am new to this as I've mentioned before, and I really want to learn this. I appreciate your patience.

Thanks.

Tonya


RE: Nothing happens - its a simple multiplication table! - snippsat - Mar-30-2018

(Mar-30-2018, 03:57 PM)tjnichols Wrote: Alright - changes made - it still doesn't work.
doesn't work tell us nothing at all,has always been a hopeless statement in programming question.
What happens when you run code,do you get Traceback or dos something happens at all?
Copy your latest code and run it,no changes at all.
Output:
λ python -V Python 3.6.4 E:\1py_div\div_code λ python multi.py Width: 5 Height: 4 1 2 3 4 5 2 4 6 8 10 3 6 9 12 15 4 8 12 16 20



RE: Nothing happens - its a simple multiplication table! - tjnichols - Mar-30-2018

Ok - no changes as in nothing happens. It just goes back to the command prompt. If I am using Python, it just goes back the same prompt as I have when I started it.


RE: Nothing happens - its a simple multiplication table! - Larz60+ - Mar-31-2018

Quote:It just goes back to the command prompt.
Please be more verbose in your statements!
Show all commands verbatim, and
all results verbatim.
It's not fair to make us guess at an answer.


RE: Nothing happens - its a simple multiplication table! - tjnichols - Mar-31-2018

I wasn't trying to make you or anyone else guess. I believe all of our time to be much more valuable than that. I have given you everything I have with all of the information I have with the inclusion of the lack of errors, etc.


RE: Nothing happens - its a simple multiplication table! - snippsat - Mar-31-2018

(Mar-30-2018, 08:03 PM)tjnichols Wrote: Ok - no changes as in nothing happens. It just goes back to the command prompt.
Goes back from what,do you run in cmd or do you use Linux?

In top line of this site click on >Code.
I copy and paste code from your post and push run button.
As you see in image it run fine,so the problem is on your side.

You have to explain all step you do.
Example i have Windows and Python 3.6 installed i open cmd and try to run with this command ....,
but nothing happened.

[Image: qcWX53.jpg]