Previous Post :
Python #16-Getting Multiple Inputs In Python Lists
Next Post :
Python #18-Counting the Number of Digits in a Number
Tables:
2 X 1 =2
2 X 2 =4
2 X 3 =6
2 X 4 =8
2 X 5 =10
2 X 6 = 12
2 X 7 = 14
2 X 8 = 16
2 X 9 = 18
2 X 10 =20
Source Code:
number = int(input("Enter the number to print its table :"))
mul = 'X'
equal = '='
if(number != 0):
for i in range (1, 11):
print number, mul, i, equal, number*i
else :
print "Zero X anything will be Zero"
Output:
Test case 1:
Enter the number to print its table: 2
2 X 1 =2
2 X 2 =4
2 X 3 =6
2 X 4 =8
2 X 5 =10
2 X 6 = 12
2 X 7 = 14
2 X 8 = 16
2 X 9 = 18
2 X 10 =20
Test case 2:
Enter the number to print its table: 0
Zero X anything will be Zero
Explanation:
1. Getting the number from the User Keyboard.
2. Checking whether the given number is not equal to Zero.
3. If the number is Zero then printing the statement "Zero X anything will be Zero"
4. If the number is Not equal to Zero. Then by using the for loop range(1, 11) Performing the multiplication operation number * i.
Eg: print number, mul, i, equal, number *i
5. End.
Python #16-Getting Multiple Inputs In Python Lists
Next Post :
Python #18-Counting the Number of Digits in a Number
Tables:
2 X 1 =2
2 X 2 =4
2 X 3 =6
2 X 4 =8
2 X 5 =10
2 X 6 = 12
2 X 7 = 14
2 X 8 = 16
2 X 9 = 18
2 X 10 =20
Come let's Try this in Python..
Source Code:
number = int(input("Enter the number to print its table :"))
mul = 'X'
equal = '='
if(number != 0):
for i in range (1, 11):
print number, mul, i, equal, number*i
else :
print "Zero X anything will be Zero"
Output:
Test case 1:
Enter the number to print its table: 2
2 X 1 =2
2 X 2 =4
2 X 3 =6
2 X 4 =8
2 X 5 =10
2 X 6 = 12
2 X 7 = 14
2 X 8 = 16
2 X 9 = 18
2 X 10 =20
Test case 2:
Enter the number to print its table: 0
Zero X anything will be Zero
Explanation:
1. Getting the number from the User Keyboard.
2. Checking whether the given number is not equal to Zero.
3. If the number is Zero then printing the statement "Zero X anything will be Zero"
4. If the number is Not equal to Zero. Then by using the for loop range(1, 11) Performing the multiplication operation number * i.
Eg: print number, mul, i, equal, number *i
5. End.
Thanks and regards,
Tech bird
Comments