-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpuzzle.py
34 lines (24 loc) · 962 Bytes
/
puzzle.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/env python3
import random
weights = [2] * 12
which = random.randrange(1, 13)
heavier = random.randrange(0, 2) == 0
weights[which - 1] = 1.5 + heavier
for turn in range(3):
left = [int(x.strip()) for x in input("Enter marbles to weigh in left side of balance, space-separated\n").split(" ")]
right = [int(x.strip()) for x in input("Enter marbles to weigh in right side of balance, space-separated\n").split(" ")]
left_weight = sum([weights[i - 1] for i in left])
right_weight = sum([weights[i - 1] for i in right])
if left_weight > right_weight:
print("Left side is heavier!")
elif left_weight < right_weight:
print("Right side is heavier!")
else:
print("Sides are equal!")
print()
guess = int(input("Which marble? "))
heavier_guess = input("Heavier or lighter? ").lower() == "heavier"
if guess == which and heavier_guess == heavier:
print("Correct!")
else:
print("Incorrect!")