uaveiro-leci/1ano/1semestre/fp/aula03/poly.py

29 lines
541 B
Python
Raw Permalink Normal View History

2022-10-11 19:27:51 +00:00
# Esta função implementa g(x) = 8 - x**3
2023-01-30 16:48:43 +00:00
def g(x):
return 8 - x ** 3
2023-01-30 16:48:43 +00:00
2022-10-11 19:27:51 +00:00
# Defina uma função que implemente p(x) = x**2 + 2x + 3
2023-01-30 16:48:43 +00:00
def p(x):
return x ** 2 + 2 * x + 3
2023-01-30 16:48:43 +00:00
2022-10-11 19:27:51 +00:00
def main():
# Mostra alguns valores da função g:
print("g(1) =", g(1))
print("g(2) =", g(2))
print("g(10) =", g(10))
# Acrescente instruções para mostrar os valores de
# p(1), p(2), p(10) e g(1 + p(3)).
2022-10-18 17:18:56 +00:00
print(f"""
p(1) = {p(1)}
p(2) = {p(2)}
p(10) = {p(10)}
g(1 + p(3)) = {g(1 + p(3))}
""")
2022-10-11 19:27:51 +00:00
2023-01-30 16:48:43 +00:00
2022-10-11 19:27:51 +00:00
if __name__ == '__main__':
main()