-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcat.py
More file actions
57 lines (44 loc) · 1.79 KB
/
cat.py
File metadata and controls
57 lines (44 loc) · 1.79 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import generals
import math
def get_valid_positive_integer():
"""Get and validate a positive integer from user input."""
while True:
user_input = input("How many times should the cat meow? ").strip()
# Check if it's a valid integer
if not generals.is_integer(user_input):
print(f"'{user_input}' is not a valid whole number. Please enter a positive integer.")
continue
# Convert to integer and check if positive
number = int(user_input)
if number <= 0:
print("Please enter a number greater than zero.")
continue
return number
def meows_generator(total):
"""Generate meows with special quarter-point meows."""
# --- Pre-calculate the quarter points (improved logic) ---
# We use list comprehension and the ceil function for reliable rounding up,
# ensuring that 1/4 of 10 (2.5) is marked at 3, not 2.
# The set() removes duplicates automatically.
quarter_points = {
math.ceil(total * 0.25),
math.ceil(total * 0.50),
math.ceil(total * 0.75),
total # Always include the final meow
}
print(f"\n--- Starting Meow Sequence (Total: {total}) ---")
# --- Meow Loop ---
# The 'range(total)' provides numbers from 0 up to (total - 1)
for i in range(total):
meows_counter = i + 1 # Convert 0-based index to 1-based count
if meows_counter in quarter_points:
print(f"{meows_counter}: Meoooooowwwwww!")
else:
print(f"{meows_counter}: Meow")
def main():
# Get validated input first
total_meows = get_valid_positive_integer()
# Then generate meows with the validated number
meows_generator(total_meows)
if __name__ == "__main__":
main()