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

if __name__ == '__name__':
well it will never be, use:
if __name__ == '__main__':
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.
Look again (part in quotation marks)!
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
(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
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.
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.
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.
(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]](https://imagizer.imageshack.com/v2/xq90/923/qcWX53.jpg)