6dd0bb0module-03(ex2): remove usage of len
1 file changed, +11, -7
author
mogi <git@mogiya.dev> on 15-05-2026 16:10 UTC+1
committer
mogi <git@mogiya.dev> on 15-05-2026 16:21 UTC+1
parent3736d51
    @@ -4,21 +4,25 @@ import math
 4 4 def get_player_pos() -> tuple[float, float, float] | None:
 5 5     while True:
 6 6         try:
 7  -            coordinates = input(
   7+            raw = input(
 8 8                 "Enter new coordinates as floats in format 'x,y,z': "
 9  -            ).split(',')
10  -        except KeyboardInterrupt:
   9+            )
  10+            x_str, y_str, z_str = raw.split(',')
  11+        except (KeyboardInterrupt, EOFError):
1112             print("\nProgram interrupted by user.")
1213             return None
13  -        if len(coordinates) != 3:
  14+        except ValueError:
1415             print("Invalid syntax")
1516             continue
  17+
1618         try:
17  -            res = [float(coord.strip()) for coord in coordinates]
18  -            return (res[0], res[1], res[2])
  19+            x = float(x_str.strip())
  20+            y = float(y_str.strip())
  21+            z = float(z_str.strip())
  22+            return (x, y, z)
1923         except ValueError as error:
2024             invalid_input = ""
21  -            for coord in coordinates:
  25+            for coord in (x_str, y_str, z_str):
2226                 try:
2327                     float(coord.strip())
2428                 except ValueError: