-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions_notes_1_starter.py
More file actions
61 lines (45 loc) · 1.91 KB
/
functions_notes_1_starter.py
File metadata and controls
61 lines (45 loc) · 1.91 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
"""
Name:
Title: Functions Basics
"""
# A FUNCTION is a reusable block of code that performs a specific task.
# Functions allow you to abstract away unnecessary information and leverage modular design.
# Built-in functions we know: print(), input(), len(), random.randint(), etc.
# ABSTRACTION is hiding all but the most relevant details.
# Lets you think about the big picture without worrying about the details.
# e.g. variable or function names are an abstraction of their actual contents.
# 1: Creating a function is referred to as...
# FUNCTION DEFINITION is the entire function, both header and body.
# ...
# 2: Using a function is referred to as
# "Calling a function"
# ...
# 3: DOCSTRING. A special way to document a function;
# It must be triple quoted, and on the first line. Can provide
# useful info when attempting to use the function.
# ...
# 4: PARAMETERS: Variable names inside the parentheses of a
# function header. A function receives a value through its
# parameters. Parameters catch values sent to the function
# from a function call.
# ARGUMENTS: Values sent to a function to use. (put in parentheses of a
# function call)
# ...
# Trap... If I define a function with one parameter, then I must
# use the same number of arguments when calling the function
# 5 You can have multiple parameters:
# ...
# 6: You can get values out of a function by returning value(s).
# You can return a value from a function by using
# the RETURN STATEMENT. A function always ends after
# executing a return statement, and the RETURN VALUE is returned.
# ...
# You can return any type of value in a function
# ...
# CHALLENGE 1: Can you define a function that can simulate
# the rolling of two dies and return both values?
# ...
# CHALLENGE 2: Create a new function to add your two die rolls
# together and return the total.
# ...
input("Press enter to exit.")