From 11b1260b56ed8b95744ad820f5c5ead173903090 Mon Sep 17 00:00:00 2001 From: tiagorg Date: Tue, 18 Oct 2022 18:18:56 +0100 Subject: [PATCH] formatting changes --- 1ano/fp/aula01/ex02.py | 2 +- 1ano/fp/aula01/ex04.py | 5 +-- 1ano/fp/aula01/ex06.py | 2 +- 1ano/fp/aula01/ex07.py | 2 +- 1ano/fp/aula02/darts.py | 68 +++++++++++++++++++----------------- 1ano/fp/aula02/ex02_03.py | 2 +- 1ano/fp/aula02/ex09.py | 2 +- 1ano/fp/aula03/bmi.py | 4 +-- 1ano/fp/aula03/dates.py | 3 +- 1ano/fp/aula03/ex05_06.py | 19 ++++++---- 1ano/fp/aula03/ex12.py | 13 +++---- 1ano/fp/aula03/ex13.py | 5 +-- 1ano/fp/aula03/poly.py | 10 +++--- 1ano/fp/aula04/divs-cate.py | 28 +++++++-------- 1ano/fp/aula04/factorial.py | 3 +- 1ano/fp/aula04/fibonacci.py | 5 +-- 1ano/fp/aula04/hilo.py | 8 +++-- 1ano/fp/aula04/leibnizPi4.py | 12 +++---- 1ano/fp/aula04/media.py | 15 ++++---- 1ano/fp/aula04/turtle1.py | 3 +- 20 files changed, 111 insertions(+), 100 deletions(-) diff --git a/1ano/fp/aula01/ex02.py b/1ano/fp/aula01/ex02.py index 12d5717..8ea93fc 100644 --- a/1ano/fp/aula01/ex02.py +++ b/1ano/fp/aula01/ex02.py @@ -2,4 +2,4 @@ celcius = float(input('°C: ')) fahrenheit = 1.8 * celcius + 32 -print('\n{} °C = {} °F'.format(celcius, fahrenheit)) \ No newline at end of file +print(f'\n{celcius} °C = {fahrenheit} °F') \ No newline at end of file diff --git a/1ano/fp/aula01/ex04.py b/1ano/fp/aula01/ex04.py index b77d4b5..094ab6d 100644 --- a/1ano/fp/aula01/ex04.py +++ b/1ano/fp/aula01/ex04.py @@ -1,8 +1,5 @@ -import calendar -from datetime import datetime; - nome = input('Como te chamas? ') anoNascenca = int(input('Em que ano nasceste? ')) ano = int(input('Ano para verificar: ')) -print('{}, em {} farás {} anos.'.format(nome, ano, ano - anoNascenca)) \ No newline at end of file +print(f'{nome}, em {ano} farás {ano - anoNascenca} anos.') \ No newline at end of file diff --git a/1ano/fp/aula01/ex06.py b/1ano/fp/aula01/ex06.py index 03d73d9..76b6794 100644 --- a/1ano/fp/aula01/ex06.py +++ b/1ano/fp/aula01/ex06.py @@ -7,4 +7,4 @@ kmAno = mAno secsAno = mAno hAno = secsAno / 3600 -print('O elevador anda {} kilometros por ano, durante {} horas.'.format(kmAno, hAno)) +print(f'O elevador anda {kmAno} kilometros por ano, durante {hAno} horas.') diff --git a/1ano/fp/aula01/ex07.py b/1ano/fp/aula01/ex07.py index bdd6d24..83ac698 100644 --- a/1ano/fp/aula01/ex07.py +++ b/1ano/fp/aula01/ex07.py @@ -10,4 +10,4 @@ cosseno = A / C angRad = acos(cosseno) angDeg = angRad * 180 / pi -print('O comprimento da hipotenusa é {} e o valor do angulo entre o cateto A e a hipotenusa é {}°'.format(round(C, 2), round(angDeg, 2))) \ No newline at end of file +print(f'O comprimento da hipotenusa é {round(C, 2)} e o valor do angulo entre o cateto A e a hipotenusa é {round(angDeg, 2)}°') \ No newline at end of file diff --git a/1ano/fp/aula02/darts.py b/1ano/fp/aula02/darts.py index 9423b16..4a6b09e 100644 --- a/1ano/fp/aula02/darts.py +++ b/1ano/fp/aula02/darts.py @@ -1,5 +1,39 @@ import math +def main(): + print("""Introduza as coordenadas (x, y) do dardo. +Representa as posicoes horizontal e vertical respetivamente. +Ambas em milimetros. + """) + + x = int(input('X: ')) + y = int(input('Y: ')) + + mod = math.sqrt(x ** 2 + y ** 2) + + if mod > 170: + print('Fora do alvo.') + exit(1) + + if mod < 12.7: + print('Pontuacao: 50 pontos.') + exit(1) + elif mod < 32: + print('Pontuacao: 25 pontos.') + exit(1) + + base_point = BasePoint(x, y) + + if mod > 99 and mod < 107: + print('Pontuacao: {}pontos.'.format(base_point * 3)) + exit(1) + if mod > 162: + print('Pontuacao: {}pontos.'.format(base_point * 2)) + exit(1) + + print('Pontuacao: {}pontos.'.format(base_point)) + exit(1) + def BasePoint(x, y): if x > 0: if abs(y) < x * math.tan(math.pi / 20): @@ -54,35 +88,5 @@ def BasePoint(x, y): else: return 3 -print("""Introduza as coordenadas (x, y) do dardo. -Representa as posicoes horizontal e vertical respetivamente. -Ambas em milimetros. -""") - -x = int(input('X: ')) -y = int(input('Y: ')) - -mod = math.sqrt(x ** 2 + y ** 2) - -if mod > 170: - print('Fora do alvo.') - exit(1) - -if mod < 12.7: - print('Pontuacao: 50 pontos.') - exit(1) -elif mod < 32: - print('Pontuacao: 25 pontos.') - exit(1) - -base_point = BasePoint(x, y) - -if mod > 99 and mod < 107: - print('Pontuacao: {}pontos.'.format(base_point * 3)) - exit(1) -if mod > 162: - print('Pontuacao: {}pontos.'.format(base_point * 2)) - exit(1) - -print('Pontuacao: {}pontos.'.format(base_point)) -exit(1) \ No newline at end of file +if __name__ == '__main__': + main() \ No newline at end of file diff --git a/1ano/fp/aula02/ex02_03.py b/1ano/fp/aula02/ex02_03.py index d1d4c4c..66be19a 100644 --- a/1ano/fp/aula02/ex02_03.py +++ b/1ano/fp/aula02/ex02_03.py @@ -11,4 +11,4 @@ if x2 > mx: if x3 > mx: mx = x3 -print("Maximum:", mx) \ No newline at end of file +print("Maximum: ", mx) \ No newline at end of file diff --git a/1ano/fp/aula02/ex09.py b/1ano/fp/aula02/ex09.py index ab09dc5..658122a 100644 --- a/1ano/fp/aula02/ex09.py +++ b/1ano/fp/aula02/ex09.py @@ -14,6 +14,6 @@ ATPR = float(input('Componente Teorica-pratica de recurso: ')) ATP = float(input('Componente Pratica de recurso: ')) NF = round(0.3 * ATPR + 0.7 * ATP) if NF >= 10: - print('Aprovado com nota {}'.format(NF)) + print('Aprovado com nota ', NF) else: print('Continua reprovado, nota ', NF) \ No newline at end of file diff --git a/1ano/fp/aula03/bmi.py b/1ano/fp/aula03/bmi.py index 3ae8903..25b3492 100644 --- a/1ano/fp/aula03/bmi.py +++ b/1ano/fp/aula03/bmi.py @@ -45,5 +45,5 @@ def main(): # Program starts executing here -main() - +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/1ano/fp/aula03/dates.py b/1ano/fp/aula03/dates.py index c0c70b2..3fb026a 100644 --- a/1ano/fp/aula03/dates.py +++ b/1ano/fp/aula03/dates.py @@ -71,4 +71,5 @@ def main(): print(y, m, d) # 2018 1 1 ? # call the main function -main() +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/1ano/fp/aula03/ex05_06.py b/1ano/fp/aula03/ex05_06.py index 935180a..0d9ffc4 100644 --- a/1ano/fp/aula03/ex05_06.py +++ b/1ano/fp/aula03/ex05_06.py @@ -7,13 +7,18 @@ def max2(x, y): def max3(x, y, z): return max2(x, max2(y, z)) -n1 = float(input('Introduza dois valores.\nN1: ')) -n2 = float(input('N2: ')) +def main(): + n1 = float(input('Introduza dois valores.\nN1: ')) + n2 = float(input('N2: ')) -print('\nO maior valor é: ', max2(n1, n2)) + print('\nO maior valor é: ', max2(n1, n2)) -n1 = float(input('\n\nIntroduza tres valores.\nN1: ')) -n2 = float(input('N2: ')) -n3 = float(input('N3: ')) + n1 = float(input('\n\nIntroduza tres valores.\nN1: ')) + n2 = float(input('N2: ')) + n3 = float(input('N3: ')) -print('\nO maior valor é: ', max3(n1, n2, n3)) \ No newline at end of file + print('\nO maior valor é: ', max3(n1, n2, n3)) + + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/1ano/fp/aula03/ex12.py b/1ano/fp/aula03/ex12.py index 0905a7d..227d9d1 100644 --- a/1ano/fp/aula03/ex12.py +++ b/1ano/fp/aula03/ex12.py @@ -1,11 +1,12 @@ def main(): num = int(input('De onde vai começar o contador? ')) - countdown(num) + for n in countdown(num): + print(n) def countdown(n): - assert n > 0 - print(n) - if n > 0: - countdown(n - 1) + while n > 0: + yield n + n -= 1 -main() \ No newline at end of file +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/1ano/fp/aula03/ex13.py b/1ano/fp/aula03/ex13.py index 85bfc61..371ad6c 100644 --- a/1ano/fp/aula03/ex13.py +++ b/1ano/fp/aula03/ex13.py @@ -11,6 +11,7 @@ def main(): print('Este programa calcula o máximo divisor comum de dois námeros naturais') n1 = int(input('Numero 1: ')) n2 = int(input('Numero 2: ')) - print('\nO Máximo Divisor Comum de \'{}\' e \'{}\' é: {}'.format(n1, n2, mdc(n1, n2))) + print(f'\nO Máximo Divisor Comum de {n1} e {n2} é: {mdc(n1, n2)}') -main() \ No newline at end of file +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/1ano/fp/aula03/poly.py b/1ano/fp/aula03/poly.py index 2399aef..aa62f8b 100644 --- a/1ano/fp/aula03/poly.py +++ b/1ano/fp/aula03/poly.py @@ -12,10 +12,12 @@ def main(): # Acrescente instruções para mostrar os valores de # p(1), p(2), p(10) e g(1 + p(3)). - print("""p(1) = {} -p(2) = {} -p(10) = {} -g(1 + p(3)) = {}""".format(p(1), p(2), p(10), g(1 + p(3)))) + print(f""" +p(1) = {p(1)} +p(2) = {p(2)} +p(10) = {p(10)} +g(1 + p(3)) = {g(1 + p(3))} +""") if __name__ == '__main__': main() diff --git a/1ano/fp/aula04/divs-cate.py b/1ano/fp/aula04/divs-cate.py index cae9470..e8a164c 100644 --- a/1ano/fp/aula04/divs-cate.py +++ b/1ano/fp/aula04/divs-cate.py @@ -3,43 +3,39 @@ def main(): n = int(input('Introduza um número: ')) div_list_array = divList(n) - # Transforma a lista obtida numa string para imprimir - div_list = "" - for div in div_list_array: - div_list += (str(div) + ', ') - div_list = div_list[:len(div_list)-2] - # --- + div_list = ", ".join(div_list_array) - print(""" + print(f""" -------------------- -Número introduzido: {} +Número introduzido: {n} Lista de divisores: -{} +{div_list} -Este é um número {}. +Este é um número {category(n, div_list_array)}. -------------------- - -""".format(n, div_list, category(n, div_list_array))) + +""") # Obtém uma lista com todos os dividores de um número def divList(n): divs = [] for x in range(1, n): if n % x == 0: - divs.append(x) + divs.append(str(x)) return divs # Obtém a categoria de um número def category(n, divs): total = 0 for div in divs: - total += div + total += int(div) if total < n: return 'deficiente' if total == n: return 'perfeito' - if total > n: return 'abundante' + if total > n: return 'abundante' -main() \ No newline at end of file +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/1ano/fp/aula04/factorial.py b/1ano/fp/aula04/factorial.py index 41cad40..1173189 100644 --- a/1ano/fp/aula04/factorial.py +++ b/1ano/fp/aula04/factorial.py @@ -8,4 +8,5 @@ def main(): n = int(input('Introduza um número: ')) print('O fatorial de {} é: {}'.format(n, factorial(n))) -main() \ No newline at end of file +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/1ano/fp/aula04/fibonacci.py b/1ano/fp/aula04/fibonacci.py index f0ca974..4882725 100644 --- a/1ano/fp/aula04/fibonacci.py +++ b/1ano/fp/aula04/fibonacci.py @@ -5,6 +5,7 @@ def fibonacci(n): def main(): n = int(input('Introduza um número: ')) - print('O {}º número de Fibonacci é: {}'.format(n, fibonacci(n))) + print(f'O {n}º número de Fibonacci é: {fibonacci(n)}') -main() \ No newline at end of file +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/1ano/fp/aula04/hilo.py b/1ano/fp/aula04/hilo.py index 343b1b5..c8b118a 100644 --- a/1ano/fp/aula04/hilo.py +++ b/1ano/fp/aula04/hilo.py @@ -8,6 +8,7 @@ def main(): print("Can you guess my secret?") # put your code here c = 0 + trieslist = [] num = -1 while secret != num: num = int(input('>>> ')) @@ -16,6 +17,9 @@ def main(): if num < secret: print('Low') c += 1 - print('Well done! The secret number was {}. It took you {} tries to get it right.'.format(secret, c)) + trieslist.append(str(num)) + triesstr = ', '.join(trieslist) + print(f'Well done! The secret number was {secret}. It took you {c} tries to get it right.\nList of tries: {triesstr}') -main() +if __name__ == "__main__": + main() diff --git a/1ano/fp/aula04/leibnizPi4.py b/1ano/fp/aula04/leibnizPi4.py index 023a3e6..1fc93d5 100644 --- a/1ano/fp/aula04/leibnizPi4.py +++ b/1ano/fp/aula04/leibnizPi4.py @@ -1,6 +1,5 @@ import math - def leibnizPi4(n): total = 0 for x in range(1, n+1): @@ -12,9 +11,10 @@ def leibnizPi4(n): def main(): num = int(input('Introduza o número de termos: ')) - print(""" -Resultado da série de Leibniz: {} -Valor do PI/4: {} -""".format(leibnizPi4(num), math.pi/4)) + print(f""" +Resultado da série de Leibniz: {leibnizPi4(num)} +Valor do PI/4: {math.pi/4} +""") -main() \ No newline at end of file +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/1ano/fp/aula04/media.py b/1ano/fp/aula04/media.py index 563d74c..d3f6b2f 100644 --- a/1ano/fp/aula04/media.py +++ b/1ano/fp/aula04/media.py @@ -1,25 +1,22 @@ -# Cria uma lista acessivel por todas as funções -values = [] - # Pede ao utilizadores todas as parcelas e adiciona-as à lista 'values' def GetValues(): c = 1 + values = [] while True: n = input('n{}: '.format(c)) if n == "": break values.append(float(n)) c += 1 + return values # Calcula a média dos valores da lista 'values' def GetMedia(val): - total = 0 - for v in val: - total += v - return total / len(val) + return sum(val) / len(val) # Função principal def main(): - GetValues() + values = GetValues() print('Média dos valores introduzidos: ', GetMedia(values)) -main() \ No newline at end of file +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/1ano/fp/aula04/turtle1.py b/1ano/fp/aula04/turtle1.py index f000530..c4594ad 100644 --- a/1ano/fp/aula04/turtle1.py +++ b/1ano/fp/aula04/turtle1.py @@ -61,4 +61,5 @@ def main(): print("The window was closed. Bye!") -main() +if __name__ == "__main__": + main()