-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path04_functions_and_more.py
85 lines (50 loc) · 1.84 KB
/
04_functions_and_more.py
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
# def keyword used to defin a function
def function_testing(name):
print(f"Test print function {name}")
# calling the function is required to execute the existing code
function_testing("Benjamin$$")
# looping over a range and use the function_testing() call to to the code for range ammount of times
# for x in range(50):
# function_testing()
# parameters - a way to pass information in to the function
def add_numbers(num1, num2):
print(num1 + num2)
add_numbers(1234, 555)
# Challange dog func that takes age and name and prints the complete data
def dog_data(name, age):
print(f"The dog's name is {name} and he is {age} old")
dog_data("Random Dog", 11)
# returning the func values
def multiplications(num):
return num * 11
test_num = multiplications(55)
print(test_num)
# Challange - create a func that returns a string in all caps
def upper_case(var):
return var.upper()
upper_case("test string this")
names = ["ben", "Jhon", "arthur"]
for name in names:
print(upper_case(name))
# comments are a very import thing in to code blocks to hold main ideas or processe
# # -> used to coment a line that will be in the file but not executed
# Inputs -> requesting the user for an input
# asking the user to input some text
user_text = input("enter some text: ")
print(user_text.upper())
# Input from the console is always a string !!!
user_selection = input("do you want it uppercased? y / n: ")
if user_selection == "y":
print(user_text.upper())
else:
print(user_text.lower())
# Coding Challange - Is there a remainder?
# num1 = 1122334455
# num2 = 55
# num1 and num2 - passed when calling function
def has_remainder(num1, num2):
if num1 % num2 == 0:
return False
else:
return True
has_remainder(1122334455, 55)