-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction_examples.py
More file actions
55 lines (46 loc) · 1.48 KB
/
function_examples.py
File metadata and controls
55 lines (46 loc) · 1.48 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
###########################################################
# Example #1 Without a function. #
###########################################################
age = int(input('How old are you? '))
if age >= 21:
print('Access Granted...')
else:
print('Access Denied...')
###########################################################
# Example #2 With a main runtime function. #
###########################################################
def main():
age = int(input('How old are you? '))
if age >= 21:
print('Access Granted...')
else:
print('Access Denied...')
main()
###########################################################
# Example #3 Function performs the print action #
###########################################################
def verify_age(age):
if age >= 21:
print('Access Granted...')
else:
print('Access Denied...')
def main():
age = int(input('How old are you? '))
verify_age(age)
main()
###########################################################
# Example #4 Function returns true or false and the main #
# runtime function does the printing. #
###########################################################
def verify_age(age):
if age >= 21:
return True
else:
return False
def main():
age = int(input('How old are you? '))
if verify_age(age):
print('Access Granted...')
else:
print('Access Denied...')
main()