-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.py
More file actions
102 lines (67 loc) · 2.69 KB
/
functions.py
File metadata and controls
102 lines (67 loc) · 2.69 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# What is a function?
# Why should we use a function
# What is the benefit - REUSABLE block of code
# D R Y - Do Not Repeat Yourself
# What functions have we used so far? - print(), type(), str(), int()
# Syntax: def name_of_function with () and :
# Create a function to greet
# def greeting():
# return "Hello world"
# pass # pass will skip the function, tells the python operator to skip the function, no errors will apear.
# print(greeting()) # We can use print to call the function
#def test():
# pass # Pass will skip the methods and there will be no outcome.
# Pass is used in created or building a unit test.
# Methods with parameters/arguments
# def add_values():
# return 4 + 4 # We can return anything - Strings, int with + operator
#
# print(add_values())
# def add_values(number1, number2): # Passing the function an argument of 2 numbers
# return number1 + number2 # This returns the values of Number1 + Number2
#
# print(add_values(4,9)) # Print will then return the value of the numbers passed into the argument
# Divide function
def divide_values(number1, number2): # Passing the function an argument of 2 numbers
return number1 / number2 # This returns the values of Number1 + Number2
#
print(divide_values(4,9)) # Print will then return the value of the numbers passed into the argument
# create a function with two args to return a subtraction of the 2 values given
def subtract(num1, num2):
return num1 - num2
print(subtract(10,2))
# create a function with two args to return a division of the 2 values given
def divide(num1, num2):
return num1 / num2
print(divide(100,10))
# create a function with two args to return a remainder of of the 2 values given
def remainder(num1, num2):
return num1 % num2
print(remainder(100,7))
# create a function with two args to return a * of the 2 values given
def multiply(num1, num2):
return num1 * num2
print(multiply(10,7))
# User input multiply
num1 = int(input("Please enter a number"))
num2 = int(input("Please enter a 2nd number"))
def multiply (num1, num2):
return num1 * num2
print(multiply(num1, num2))
# User input divide
num1 = int(input("Please enter a number"))
num2 = int(input("Please enter a number"))
def divide(num1, num2):
return num1 / num2
print(divide(num1, num2))
# User input add
num1 = int(input("Please enter a number"))
num2 = int(input("Please enter a number"))
def add(num1, num2):
return num1 + num2
print(add(num1, num2))
def multi_args(*multiargs): # Here we have given multiple arguments
for args in multiargs: # This will iterate through the arguments
print(args)
return args # Return will end the function
print(multi_args(1, 2, 2, 3, 3, 4, 4, 5, ))