-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path04_30.py
More file actions
81 lines (53 loc) · 1.02 KB
/
04_30.py
File metadata and controls
81 lines (53 loc) · 1.02 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
'''
dictionaries
translations = {"hello": "hola", "bye": "adios", "thank you": "gracias"}
print(translations["hello"])
'''
'''
try/except raise an exception
string = "whatever"
try:
num = int(string)
except ValueError as err:
print("The string is not a number", err)
'''
'''
File I/O
file = open("example.txt", "w")
file.writelines("Yes I also like coding in python and java")
file.close()
content = open("example.txt", "r")
print(content.read())
'''
'''
Functions
def sq (num):
return num * num
def main():
sq(x)
if __name__ == "__main__":
print(sq(3))
'''
'''
User Input
name = input("Whats your name:")
print(f"My name is {name}")
'''
'''
Lists
ord = [1, {"Haha": "Laughing", "Sad": "Emotional"}, 'LOL']
print(ord)
print(ord[0])
ord[1] = 5
print(ord)
'''
'''
Loops
fruits = ["apple", "banana", "oranges"]
for i in fruits:
print(i)
i = 0
while i < len(fruits):
print(fruits[i])
i += 1
'''