-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathteste_condicional.py
More file actions
60 lines (50 loc) · 1.45 KB
/
teste_condicional.py
File metadata and controls
60 lines (50 loc) · 1.45 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
fruits = ['laranja','banana','maçã', 'melancia', 'mamão', 'melão']
for fruit in fruits:
if fruit == 'melancia':
print(fruit.upper())
else:
print(fruit.lower())
# Operadores lógicos
# AND
# OR
# Operadores aritméticos
# +
# -
# *
# /
# Operadores de igualdade
# ==
# !=
# Operadores lógico matemáticos
# >
# <
# >=
# <=
# % -> resto da divisão
# Operador in verifica se determinado valor está presente em uma lista e not in o inverso
search_for_fruit = "melão" in fruit
print("Search for fruit: " + str(search_for_fruit))
search_for_fruit = "goiaba" in fruit
print("Search for fruit: " + str(search_for_fruit))
search_for_fruit = "melão" not in fruit
print("Search for fruit: " + str(search_for_fruit))
search_for_fruit = "goiaba" not in fruit
print("Search for fruit: " + str(search_for_fruit))
# Se senão se
for fruit in fruits:
if fruit == "banana" or fruit == "melao":
print("Fruta amarela")
elif fruit == "melancia" or fruit == "maçã":
print("Fruta vermelha")
else:
print("Outra cor de fruta")
# Para verificar se uma lista está vazia basta utilizar o nome dela em uma condição
new_fruits = []
if new_fruits:
print('Possui elemento em new fruits')
else:
print('Não possui elementos em new fruits')
if fruits:
print('Possui elemento em fruits')
else:
print('Não possui elemento em fruits')