-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay20.py
More file actions
73 lines (50 loc) · 1.38 KB
/
Day20.py
File metadata and controls
73 lines (50 loc) · 1.38 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# Functions
# A function is a block of code that performs a specific task whenever it is called.
# In bigger programs, where we have large amount of code, it is advisable to create or use existing functions that make
# program flow organized and neat.
# There are two types of functions:
# 1) Built-in function.
# 2) User-defined functions
# Built inn functions:
# These functions are defined and pre-coded in python.
# eg - min(), max(), sum(), type(), range(), print()
print("Basic example: ")
a = 9
b = 8
gmean1 = (a * b) / (a + b)
print("\nGmean1 = ", gmean1)
c = 8
d = 7
gmean2 = (c * d) / (c + d)
print("\nGmean2 = ", gmean2)
# User-defined functions:
# we can create functions to perform specific tasks as per our needs.
# Syntax:
# def <function_name(parameters)>:
# function body
def calGmean(a, b):
mean = (a * b) / (a + b)
print(mean)
# now we can do:
print("\nUsing functions: ")
calGmean(a, b)
calGmean(c, d)
# Now no need to repeat same lines of code
def isGreater(a, b):
if a > b:
print("A is greater!")
else:
print("B is greater!")
def isLesser(a, b):
if a < b:
print("A is Lesser!")
else:
print("B is Lesser!")
isGreater(a, b)
isLesser(a, b)
# what if we wish to define the function at a later time
def isLesser(a, b):
pass
# here pass keyword is used else it will throw error.
# That was programs basics
# Thanks ^-^