0% found this document useful (0 votes)
3 views2 pages

Function Assignment

The document contains Python code snippets demonstrating various functions. It includes a function to add two numbers, find the square of a number, compute the square root and power using the math library, and check if a number is prime. Each function is called with example values, and the results are printed.

Uploaded by

tanushree
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

Function Assignment

The document contains Python code snippets demonstrating various functions. It includes a function to add two numbers, find the square of a number, compute the square root and power using the math library, and check if a number is prime. Each function is called with example values, and the results are printed.

Uploaded by

tanushree
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

1.

# function with two arguments


def add_numbers(num1, num2):
sum = num1 + num2
print("Sum: ", sum)
# function call with two values
add_numbers(5, 4)

2. # function definition
def find_square(num):
result = num * num
return result
# function call
square = find_square(3)
print('Square:', square)

3. import math
# sqrt computes the square root
square_root = [Link](4)
print("Square Root of 4 is",square_root)
# pow() comptes the power
power = pow(2, 3)
print("2 to the power 3 is",power)

4. def is_prime(n):
if n in [2, 3]:
return True
if (n == 1) or (n % 2 == 0):
return False
r=3
while r * r <= n:
if n % r == 0:
return False
r += 2
return True
print(is_prime(78), is_prime(79))
Output
False True

You might also like