Ai Exp 01
Ai Exp 01
No
Aim (a). Write a python program to print the multiplication table for the
given number?
(b). Write a python program to check whether the given number is
prime or not?
(c) Write a python program to find factorial of the given number?
Software PyCharm/Spyder/Colab/etc
Requirements
Code (a)# Python program to find the multiplication table (from 1 to 10) of a
number input by the user
# take input from the user
num = int(input("Display
multiplication table of? "))
# use for loop to iterate 10
times
for i in
range(
1,11):
print(
num,'
x',i,'='
,num*
i)
Theory (a) In the above program, we have taken an input integer number from
the user. Then we have iterated for loop using the range (1, 11)
function, which means greater than or equal to 1 and less than 11. In
the first iteration, the loop will iterate and multiply by 1 to the given
number. In the second iteration, 2 is multiplied by the given number,
and so on.
In our case, we have printed the table of 10. You can provide the
different numbers to test the program.
(c) The factorial of a number is the product of all the integers from 1 to
that number.
For example, the factorial of 6 is 1*2*3*4*5*6 = 720. Factorial is not
defined for negative numbers, and the factorial of zero is one, 0! = 1.
Note: To test the program for a different number, change the value
of num.
Here, the number whose factorial is to be found is stored in num, and
we check if the number is negative, zero or positive
using if...elif...else statement. If the number is positive, we
use for loop and range() function to calculate the factorial.
Result
Conclusion