IF, FOR, WHILE cicles
#Ciclos IF
title = "O capital"
title_size = len(title)
if title_size > 15:
print("Título Longo")
else:
print("Título curto")
green_flag = False
yellow_flag = False
if green_flag:
print("Let`s get that weed")
elif yellow_flag:
print ("The cops are coming")
else:
print ("They gonna fold your ass")
#Exercício
WORKS_DESCARTES = 120
WORKS_KANT = 54
if WORKS_DESCARTES > WORKS_KANT:
print("Descartes é o maior filósofo")
elif WORKS_DESCARTES < WORKS_KANT:
print ("Kant é o maior filósofo")
else:
print("Ambos são bons filósofos")
#Exercício
obra_descartes = "Meditations on First Philosophy, in which the existence of God and the immortality of the soul are demonstrated. "
obra_kant = "Über den Gemeinspruch: Das mag in der Theorie richtig sein, taugt aber nicht für die Praxis"
biggest_descartes = len(obra_descartes)
biggest_kant = len(obra_kant)
if biggest_descartes >= 20 and biggest_kant >= 20:
print ("Welcome Kanye West to the opening of the Holocaust memorial")
elif biggest_descartes > 30 or biggest_kant > 30:
print("Its very fake.")
else:
print("Yes, new Jesus.")
#ciclos while
while_limit = 10
current_index = 0
while current_index < while_limit:
print(current_index)
current_index +=1
name = "Daniela"
current_index = 0
while current_index < len(name):
if name[current_index] == "a":
print ("error")
current_index += 1
continue
print(name[current_index])
current_index +=1
print(current_index)
#Exercício 1
MAX_NOTES = 10
current_note = 4
while current_note < MAX_NOTES:
print("Dó")
current_note += 1
#Exercício 2
verso = "Oh Fortuna velut luna statu variabilis"
max_index = len(verso)
current_index = 0
while current_index < max_index:
if verso[current_index] == "u":
current_index +=1
continue
print(verso[current_index])
current_index += 1
#ciclos for num dicionário
democracia = {
"poder de escolha":"cidadão",
"poder legislativo": "parlamento",
"poder executivo":"governo",
"poder judicial":"tribunal"
}
print("Numa democracia:")
for power, entity in democracia.items():
print("O "+power+" pertence ao "+entity)
#ciclos for em sets
works={"monadologia","teodiceia","novos ensaios sobre o entendimento humano"}
for work in works:
if len(work)>15:
continue
else:
print(work)
#função range VS while
for index in range(0,10):
print(index)
index=0
#VS
while index<10:
print(index)
index+= 1
#exercício
lista_1 = ["rachmaninoff@fcsh.unl.pt", "aquino@fcsh.unl.pt", "bach@fcsh.unl.pt", "descartes@fcsh.unl.pt", "wagner@fcsh.unl.pt", "buxtehude@fcsh.unl.pt", "mozart@fcsh.unl.pt", "hume@fcsh.unl.pt"]
lista_2 = {"plotino@fcsh.unl.pt", "descartes@fcsh.unl.pt", "bach@fcsh.unl.pt", "hume@fcsh.unl.pt", "mozart@fcsh.unl.pt"}
lista_3 = [53891, 39170, 23840, 7849, 18752]
lista_4 = {72531:"dostoievski@fcsh.unl.pt", 3617:"kafka@fcsh.unl.pt", 12132:"equeiros@fcsh.unl.pt", 19281:"ortigao@fcsh.unl.pt"}
for email in lista_1:
if(len(email))>18:
print(email)
index=0
for email in lista_2:
print("Número: "+str(lista_3[index])+ " , email:"+email)
index +=1
index=0
for number,email in lista_4.items():
print("Número: "+str(number)+ " , email:"+email)