Skip to main content

Print Multiplication Tables in Python

# -*- coding: utf-8 -*-

#Created on Sat Sep 21 10:24:49 2019

# @author: MEGHA


m = int(input("How many tables you want to print?"))

n = int(input("How many tables you want to print in each row?"))

p = int(input("How many terms you want in each table?" ))

print ("\nThe MultiPlication Tables are")

print ("****************************** ")

for x in range (1,m,n):

    for y in range (1,p+1):

        for z in range (1,n+1,1) :

            if x+z-1 <= m :

                print (str(y) + " * " +str( x+z-1) + " = "+str(y*(x+z-1)), end = "\t ")

        print("")

    print("")

# end


Result:

How many tables you want to print?15

How many tables you want to print in each row?5

How many terms you want in each table?2

The MultiPlication Tables are

****************************** 

1 * 1 = 1         1 * 2 = 2         1 * 3 = 3          1 * 4 = 4          1 * 5 = 5  

2 * 1 = 2         2 * 2 = 4         2 * 3 = 6         2 * 4 = 8          2 * 5 = 10  


1 * 6 = 6          1 * 7 = 7         1 * 8 = 8         1 * 9 = 9         1 * 10 = 10  

2 * 6 = 12 2 * 7 = 14 2 * 8 = 16 2 * 9 = 18 2 * 10 = 20  


1 * 11 = 11 1 * 12 = 12 1 * 13 = 13 1 * 14 = 14 1 * 15 = 15  

2 * 11 = 22 2 * 12 = 24 2 * 13 = 26 2 * 14 = 28 2 * 15 = 30


Comments

Popular posts from this blog

Python OOPs Concepts: Using Variables and Methods

  Types of Variables in OOPs Python   Instance Variable Static Variable Local Variable   Object Level Variables Class Level Variables Method Level Variables When to use: For Every Object if you want Separate copy, use Instance Variables For all object one copy is required, use static variables Inside method, Just used for temporary requirement Where to Declare Inside the constructor method (in general) Within the class directly, outside of methods (in general)   Within the method only. How to Declare Within the constructor: Instance variables can be declared within the constructor method using the self .   Using default values : Instance variables can be assigned default values during initialization.   Outside the class: use object name.   ·          Within the class directly

Inheritance

Inheritance is a fundamental concept in object-oriented programming, which allows a class to inherit properties and methods from another class. There are several types of inheritance, including: Single Inheritance: In single inheritance, a subclass inherits properties and methods from a single parent class. The subclass is said to be derived from the parent class. Multiple Inheritance: Multiple inheritance allows a subclass to inherit properties and methods from multiple parent classes. In this case, the subclass is said to have multiple base classes. However, multiple inheritance can lead to complexity and ambiguity in the code. Multilevel Inheritance: Multilevel inheritance occurs when a subclass inherits properties and methods from a parent class, which in turn inherits from another parent class. In this case, the subclass is said to be derived from both the parent class and the grandparent class. Hierarchical Inheritance: Hierarchical inheritance occurs when multiple subclasses

Polymorphism: Method Overloading vs Method Overriding

  Method Overloading In object-oriented programming languages, method overloading enables a class to have several methods with the same name but different parameters. However, in Python, method overloading is not directly supported as opposed to languages such as Java or C++. This is because Python allows developers to define default arguments for their methods and pass arguments of any type to a method. This flexibility allows a single method to handle various types of arguments, eliminating the need for overloading.   However, there is a way to simulate method overloading in Python by using default argument values or variable length arguments and conditional statements. Here's an example: Program using default arguments:       Program using variable length arguments:   Multiple methods with Same Name: When we define multiple methods with same name, Python will consider the last defined method only. Python will not support method overloading. ( Why? Method overlo