Professional Documents
Culture Documents
WORKSHEET 1.3
1. Aim: Write a program to find perimeter and area of circle using the radius.
Code:
import math
def circle_info(radius):
Output:
2. Aim: Write a program to print multiplication table from 2 to 20 as pe the input from the
user and return corresponding values.
Code:
def print_multiplication_table(number):
for i in range(2, 21):
print(number, "x", i, "=", number * i)
print_multiplication_table(number)
Output:
Code:
def factorial(n):
if n == 0:
return 1
else:
return n * factorial(n-1)
result = factorial(n)
print("The factorial of", n, "is", result)
Output:
Code:
def square_and_cube(n):
square = n ** 2
cube = n ** 3
return (square, cube)
Output:
Code:
import math
find_roots(a, b, c)
Output:
6. Aim: If you are given 3 sticks, you may or may not be able to arrange that in a triangle.
For any three, there is a simple test to see if it is possible to from a triangle.
If any of the length is greater than the some of the other two the triangle can’t be form.
Code:
if is_triangle(a, b, c):
print("A triangle can be formed with sides of length", a, ",", b, "and", c)
else:
print("A triangle cannot be formed with sides of length", a, ",", b, "and", c)
Output: