-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconditions
More file actions
68 lines (55 loc) · 1.63 KB
/
conditions
File metadata and controls
68 lines (55 loc) · 1.63 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
#condizioni
#Equals: a == b
#Not Equals: a != b
#Less than: a < b
#Less than or equal to: a <= b
#Greater than: a > b
#Greater than or equal to: a >= b
a = 33
b = 200
if b > a:
print("b is greater than a")
c = 33
d = 33
if c > d:
print("c is greater than d")
elif c == d: # Elif si esegue sul presuposto che le condizioni precedenti sono vere
print("c and d are equal")
#La parola chiave else cattura tutto ciò che non è catturato dalle condizioni precedenti.
e = 200
f = 33
if e > f:
print("f is greater than e")
elif e == f:
print("e and f are equal")
else:
print("e is greater than f")
#Mano corta , Se hai solo un'istruzione da eseguire, puoi metterla sulla stessa riga dell'istruzione if.
#if g > h: print("g is greater than h")
#Posso avere più istruzioni sulla stessa riga
#La parola chiave and è un operatore logico e viene utilizzata per combinare istruzioni condizionali
l = 200
m = 33
n = 500
if l > m and n > l:
print("Both conditions are True")
#Verifica se aè maggiore di b, OPPURE se a è maggiore di c:
a = 200
b = 33
c = 500
if a > b or a > c:
print("At least one of the conditions is True")
#Puoi avere ifistruzioni all'interno ifdi istruzioni, questo è chiamato istruzioni nidificate if .
x = 41
if x > 10:
print("Above ten,")
if x > 20:
print("and also above 20!")
else:
print("but not above 20.")
#if le istruzioni non possono essere vuote, ma se per qualche motivo hai una ifdichiarazione senza contenuto, inseriscila passper evitare di ottenere un errore.
# mi permette di fare una condizione senza scrivere il print
k = 33
b = 200
if b > k:
pass