Python Tutorial for Beginners - How to Create Multiplication Table based on User Input

ðŸ‘Ļ‍ðŸŦ 4K | Microsoft Visual Studio 2022 - Python Tutorial for Beginners - How to Create Multiplication Table based on User Input.





Python Source Code by iBasskung.


print('Python Program to Generate Multiplication Table Demo by iBasskung.\n')

# Python While Loop
# To take input from the user
while True:
    # Python Exception Handling
    try:
        # Input upto the table number starting from 1
        n1 = int(input("Enter the first number: "))
        if(n1 <= 0):
            print('Must be a number greater than 0.\n')
            continue

        n2 = int(input("Enter the second number: "))
        if(n2 <= 0):
            print('\nInvalid input: The first and second numbers must be greater than 0.\n')
            continue
        else:
            break

    except ValueError:
        print('\nPlease input integer only...\n')
        continue

print('\nMultiplication table from 1 to ' + str(n1) + "\n")

# Increment variables value by 1.
n1 += 1
n2 = n2 + 1

# Python Nested for loop.
# outer loop
for a in range(1, n1):

    print(a, 'Tables.')
    # inner loop
    for b in range(1, n2):
        # result
        c = a * b
        print(str(a),'x','{:2d}'.format(b),'=','{:2d}'.format(c))
    print()

print('Thank you very much for watching.\n')
print('Please like and subscribe to my channel.\n')


#END


ðŸŽŊ See more:

ðŸ’Ŋ THANK YOU SO MUCH ðŸ’Ŋ



#Python #WhileLoop #ForLoop  #MultiplicationTable #VisualStudio2022 #iBasskung #ComputerProgramming

Comments

Post a Comment