forked from tecladocode/python-refresher
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode.py
More file actions
60 lines (32 loc) · 1004 Bytes
/
code.py
File metadata and controls
60 lines (32 loc) · 1004 Bytes
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
def hello():
print("Hello!")
hello()
# -- Defining vs. calling --
# It's still all sequential!
def user_age_in_seconds():
user_age = int(input("Enter your age: "))
age_seconds = user_age * 365 * 24 * 60 * 60
print(f"Your age in seconds is {age_seconds}.")
print("Welcome to the age in seconds program!")
user_age_in_seconds()
print("Goodbye!")
# -- Don't reuse names --
def print():
print("Hello, world!") # Error!
# -- Don't reuse names, it's generally confusing! --
friends = ["Rolf", "Bob"]
def add_friend():
friend_name = input("Enter your friend name: ")
friends = friends + [friend_name] # Another way of adding to a list!
add_friend()
print(friends) # Always ['Rolf', 'Bob']
# -- Can't call a function before defining it --
say_hello()
def say_hello():
print("Hello!")
# -- Remember function body only runs when the function is called --
def add_friend():
friends.append("Rolf")
friends = []
add_friend()
print(friends) # [Rolf]