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

47 lines
911 B
Python
Raw Normal View History

2022-10-11 19:27:51 +00:00
import math
2023-01-30 16:48:43 +00:00
2022-10-18 17:18:56 +00:00
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.')
2022-10-21 15:58:49 +00:00
return
2022-10-18 17:18:56 +00:00
if mod < 12.7:
print('Pontuacao: 50 pontos.')
2022-10-21 15:58:49 +00:00
return
2022-10-18 17:18:56 +00:00
elif mod < 32:
print('Pontuacao: 25 pontos.')
2022-10-21 15:58:49 +00:00
return
2022-10-18 17:18:56 +00:00
2022-10-21 15:58:49 +00:00
score = BasePoint(x, y)
2023-01-30 16:48:43 +00:00
if 99 < mod < 107:
2022-10-21 15:58:49 +00:00
score *= 3
2022-10-18 17:18:56 +00:00
if mod > 162:
2022-10-21 15:58:49 +00:00
score *= 2
print(f'Pontuacao: {score} pontos.')
2022-10-18 17:18:56 +00:00
exit(1)
2023-01-30 16:48:43 +00:00
2022-10-11 19:27:51 +00:00
def BasePoint(x, y):
2022-10-21 15:58:49 +00:00
angleRad = math.atan2(y, x)
angleDeg = math.degrees(angleRad) - 9
POINTS = (6, 13, 4, 18, 1, 20, 5, 12, 9, 14, 11, 8, 16, 7, 19, 3, 17, 2, 15, 10)
2022-10-11 19:27:51 +00:00
2022-10-21 15:58:49 +00:00
return POINTS[int(angleDeg / 20)]
2023-01-30 16:48:43 +00:00
2022-10-18 17:18:56 +00:00
if __name__ == '__main__':
2023-01-30 16:48:43 +00:00
main()