-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
62 lines (52 loc) · 1023 Bytes
/
main.py
File metadata and controls
62 lines (52 loc) · 1023 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
61
62
# variables
str = "10.0"
float = 10.0
int = 10
list = [1, 2, 3]
bool = True #/ False
# print and inputs:
print("Hello World")
toprint = input("What do you want to print? ")
print(toprint)
text = "Hello World"
print(f" texte écrit : {text}")
print("ancien format : %s" % text)
# conversion de type
int = 10
int = float(int)
int = str(int)
int = bool(int)
int = int(int)
# 2. while
variable = ""
while variable != "quit":
variable = input("Enter a value (or 'quit' to exit): ")
print(variable)
# 3. for
for i in range(5):
print(i)
# 4. if
x = 10
if x > 5:
print("x is greater than 5")
# functions
def add(a, b):
return a + b
result = add(5, 10)
print(result)
# conditional
def check_number(num):
if num > 0:
return "Positive"
elif num < 0:
return "Negative"
else:
return "Zero"
print(check_number(10))
print(check_number(-5))
print(check_number(0))
# exceptions
try:
result = 10 / 0
except ZeroDivisionError:
print("Cannot divide by zero!")