-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpractice2.py
More file actions
42 lines (42 loc) · 852 Bytes
/
Copy pathpractice2.py
File metadata and controls
42 lines (42 loc) · 852 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#FUNCTIONS
#Creating a Function
def area (l, b):
return l*b
def sum(a1, b1):
return(a1 + b1)
def add(a2, b2):
c = a2 + b2
print(c)
return
#Calling a Function
def printer(st):
print(st)
st = "I'm in a function."
printer(st)
#Return Statement
#Example 1: To add two numbers
def add(a3, b3):
sum = a3 + b3
return sum
a3 = 20
b3 = 30
sum = add(a3, b3)
print(sum)
#Example 2: To find the square of a number
def square(a):
result = a**2
return result
result = square(14)
print(result)
#Example 3: To check whether a number is prime or not
def check_prime(n):
if(n == 1):
return False
elif(n == 2):
return True
else:
for x in range(2, n):
if(n % x) == 0:
return False
return True
print(check_prime(20))