From 5680b2c4b0e08a1f13a6e2aace9c15f5b1820491 Mon Sep 17 00:00:00 2001 From: tiagorg Date: Fri, 14 Oct 2022 23:03:25 +0100 Subject: [PATCH] Exercicios da aula04 adicionados --- 1ano/fp/aula01/README.md | 5 +++++ 1ano/fp/aula02/README.md | 5 +++++ 1ano/fp/aula03/README.md | 5 +++++ 1ano/fp/aula04/README.md | 5 +++++ 1ano/fp/aula04/divs-cate.py | 39 ++++++++++++++++++++++++++++++++++++ 1ano/fp/aula04/factorial.py | 11 ++++++++++ 1ano/fp/aula04/fibonacci.py | 10 +++++++++ 1ano/fp/aula04/hilo.py | 21 +++++++++++++++++++ 1ano/fp/aula04/isprime.py | 15 ++++++++++++++ 1ano/fp/aula04/leibnizPi4.py | 20 ++++++++++++++++++ 1ano/fp/aula04/media.py | 21 +++++++++++++++++++ 1ano/fp/aula04/sequenceUn.py | 10 +++++++++ 1ano/fp/aula04/table.py | 7 +++++++ README.md | 3 ++- 14 files changed, 176 insertions(+), 1 deletion(-) create mode 100644 1ano/fp/aula01/README.md create mode 100644 1ano/fp/aula02/README.md create mode 100644 1ano/fp/aula03/README.md create mode 100644 1ano/fp/aula04/README.md create mode 100644 1ano/fp/aula04/divs-cate.py create mode 100644 1ano/fp/aula04/factorial.py create mode 100644 1ano/fp/aula04/fibonacci.py create mode 100644 1ano/fp/aula04/hilo.py create mode 100644 1ano/fp/aula04/isprime.py create mode 100644 1ano/fp/aula04/leibnizPi4.py create mode 100644 1ano/fp/aula04/media.py create mode 100644 1ano/fp/aula04/sequenceUn.py create mode 100644 1ano/fp/aula04/table.py diff --git a/1ano/fp/aula01/README.md b/1ano/fp/aula01/README.md new file mode 100644 index 0000000..db699da --- /dev/null +++ b/1ano/fp/aula01/README.md @@ -0,0 +1,5 @@ +# Fundamentos de Programação +## Aula 01 +### Tópico principal da aula: Introduction, Basics +--- +*Pode conter erros, caso encontre algum, crie um* [*ticket*](https://github.com/TiagoRG/uaveiro-leci/issues/new) \ No newline at end of file diff --git a/1ano/fp/aula02/README.md b/1ano/fp/aula02/README.md new file mode 100644 index 0000000..a1c8b89 --- /dev/null +++ b/1ano/fp/aula02/README.md @@ -0,0 +1,5 @@ +# Fundamentos de Programação +## Aula 02 +### Tópico principal da aula: Conditionals, Boolean expressions +--- +*Pode conter erros, caso encontre algum, crie um* [*ticket*](https://github.com/TiagoRG/uaveiro-leci/issues/new) \ No newline at end of file diff --git a/1ano/fp/aula03/README.md b/1ano/fp/aula03/README.md new file mode 100644 index 0000000..8325104 --- /dev/null +++ b/1ano/fp/aula03/README.md @@ -0,0 +1,5 @@ +# Fundamentos de Programação +## Aula 03 +### Tópico principal da aula: Functions, Lambda expressions +--- +*Pode conter erros, caso encontre algum, crie um* [*ticket*](https://github.com/TiagoRG/uaveiro-leci/issues/new) \ No newline at end of file diff --git a/1ano/fp/aula04/README.md b/1ano/fp/aula04/README.md new file mode 100644 index 0000000..f8e15ea --- /dev/null +++ b/1ano/fp/aula04/README.md @@ -0,0 +1,5 @@ +# Fundamentos de Programação +## Aula 04 +### Tópico principal da aula: Iteration, Loops +--- +*Pode conter erros, caso encontre algum, crie um* [*ticket*](https://github.com/TiagoRG/uaveiro-leci/issues/new) \ No newline at end of file diff --git a/1ano/fp/aula04/divs-cate.py b/1ano/fp/aula04/divs-cate.py new file mode 100644 index 0000000..470e0af --- /dev/null +++ b/1ano/fp/aula04/divs-cate.py @@ -0,0 +1,39 @@ +def divList(n): + divs = [] + for x in range(1, n): + if n % x == 0: + divs.append(x) + return divs + +def category(n): + total = 0 + for div in divList(n): + total += div + if total < n: return 'deficiente' + if total == n: return 'perfeito' + if total > n: return 'abundante' + +def main(): + n = int(input('Introduza um número: ')) + div_list = "" + div_list_array = divList(n) + for div in div_list_array: + div_list += str(div) + if div != div_list_array[len(div_list_array)-1]: + div_list += ', ' + print(""" + +-------------------- + +Número introduzido: {} + +Lista de divisores: +{} + +Este é um número {}. + +-------------------- + +""".format(n, div_list, category(n))) + +main() \ No newline at end of file diff --git a/1ano/fp/aula04/factorial.py b/1ano/fp/aula04/factorial.py new file mode 100644 index 0000000..41cad40 --- /dev/null +++ b/1ano/fp/aula04/factorial.py @@ -0,0 +1,11 @@ +def factorial(n): + total = 1 + for x in range(1, n + 1): + total *= x + return total + +def main(): + n = int(input('Introduza um número: ')) + print('O fatorial de {} é: {}'.format(n, factorial(n))) + +main() \ No newline at end of file diff --git a/1ano/fp/aula04/fibonacci.py b/1ano/fp/aula04/fibonacci.py new file mode 100644 index 0000000..f0ca974 --- /dev/null +++ b/1ano/fp/aula04/fibonacci.py @@ -0,0 +1,10 @@ +def fibonacci(n): + if n == 0: return 0 + if n == 1: return 1 + return fibonacci(n-1) + fibonacci(n-2) + +def main(): + n = int(input('Introduza um número: ')) + print('O {}º número de Fibonacci é: {}'.format(n, fibonacci(n))) + +main() \ No newline at end of file diff --git a/1ano/fp/aula04/hilo.py b/1ano/fp/aula04/hilo.py new file mode 100644 index 0000000..343b1b5 --- /dev/null +++ b/1ano/fp/aula04/hilo.py @@ -0,0 +1,21 @@ +# Complete the code to make the HiLo game... + +import random + +def main(): + # Pick a random number between 1 and 100, inclusive + secret = random.randrange(1, 101) + print("Can you guess my secret?") + # put your code here + c = 0 + num = -1 + while secret != num: + num = int(input('>>> ')) + if num > secret: + print('High') + 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)) + +main() diff --git a/1ano/fp/aula04/isprime.py b/1ano/fp/aula04/isprime.py new file mode 100644 index 0000000..a08ec00 --- /dev/null +++ b/1ano/fp/aula04/isprime.py @@ -0,0 +1,15 @@ +def isPrime(n): + div_counter = 0 + for x in range(1, n): + if n % x == 0: + div_counter += 1 + if div_counter > 1 or n == 1: + return False + else: + return True + +def main(): + for x in range(1, 100): + print('Is {} prime? {}'.format(x, isPrime(x))) + +main() \ No newline at end of file diff --git a/1ano/fp/aula04/leibnizPi4.py b/1ano/fp/aula04/leibnizPi4.py new file mode 100644 index 0000000..023a3e6 --- /dev/null +++ b/1ano/fp/aula04/leibnizPi4.py @@ -0,0 +1,20 @@ +import math + + +def leibnizPi4(n): + total = 0 + for x in range(1, n+1): + if x % 2 == 0: + total -= 1/(x*2-1) + else: + total += 1/(x*2-1) + return total + +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)) + +main() \ No newline at end of file diff --git a/1ano/fp/aula04/media.py b/1ano/fp/aula04/media.py new file mode 100644 index 0000000..f754a30 --- /dev/null +++ b/1ano/fp/aula04/media.py @@ -0,0 +1,21 @@ +values = [] + +def GetValues(): + c = 1 + while True: + n = input('n{}: '.format(c)) + if n == "": break + values.append(float(n)) + c += 1 + +def GetMedia(val): + total = 0 + for v in val: + total += v + return total / len(val) + +def main(): + GetValues() + print('Média dos valores introduzidos: ', GetMedia(values)) + +main() \ No newline at end of file diff --git a/1ano/fp/aula04/sequenceUn.py b/1ano/fp/aula04/sequenceUn.py new file mode 100644 index 0000000..674d5b1 --- /dev/null +++ b/1ano/fp/aula04/sequenceUn.py @@ -0,0 +1,10 @@ + +# This program generates 20 terms of a sequence by a recurrence relation. +Un = 100 # Un = each term of the sequence. Initially = U0 +c = 0 +while Un > 0: + print(round(Un, 4)) + Un = 1.01*Un - 1.01 # Set Un to the next term of the sequence + c += 1 + +print('O programa mostrou ', c, ' termos') diff --git a/1ano/fp/aula04/table.py b/1ano/fp/aula04/table.py new file mode 100644 index 0000000..19221dc --- /dev/null +++ b/1ano/fp/aula04/table.py @@ -0,0 +1,7 @@ +# Show a table of the squares of the first four numbers +print(" {:2s}| {:2s}| {:2s}".format("n", "n²", "2**n")) +for n in range(1, 21): + print("{:2d} | {:3d} |{:8d}".format(n, n**2, 2**n)) + +# Modify the program to show the squares of 1..20. (Use the range function.) +# Also, add a column to show 2**n. Adjust the formatting. diff --git a/README.md b/README.md index d7e07e5..4afad36 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ # UAveiro - LECI -### Todo o material de Licenciatura em Engenharia de Computatores e Informática [Free for Use] +### Todo o material de Licenciatura em Engenharia de Computatores e Informática +### [Free for Use] #### 1º Ano em 2022/2023 --- *Pode conter erros, caso encontre algum, crie um* [*ticket*](https://github.com/TiagoRG/uaveiro-leci/issues/new) \ No newline at end of file