uaveiro-leci/1ano/1semestre/fp/aula02/darts.py

34 lines
704 B
Python
Raw Normal View History

2022-10-11 19:27:51 +00:00
import math
2023-01-30 18:52:46 +00:00
POINTS = (6, 13, 4, 18, 1, 20, 5, 12, 9, 14, 11, 8, 16, 7, 19, 3, 17, 2, 15, 10)
2023-01-30 16:48:43 +00:00
print(
"Introduza as coordenadas (x, y) do dardo.\nRepresenta as posicoes horizontal e vertical respetivamente.\nAmbas em milimetros.")
2023-01-30 18:52:46 +00:00
x = int(input('X: '))
y = int(input('Y: '))
mod = math.sqrt(x ** 2 + y ** 2)
2022-10-18 17:18:56 +00:00
2023-01-30 18:52:46 +00:00
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)
2023-01-30 16:48:43 +00:00
2023-01-30 18:52:46 +00:00
angleRad = math.atan2(y, x)
angleDeg = math.degrees(angleRad) - 9
score = POINTS[int(angleDeg / 20)]
2023-01-30 16:48:43 +00:00
2023-01-30 18:52:46 +00:00
if 99 < mod < 107:
score *= 3
if mod > 162:
score *= 2
2023-01-30 16:48:43 +00:00
2023-01-30 18:52:46 +00:00
print(f'Pontuacao: {score} pontos.')
exit(1)