Skip to content

Commit 2c96062

Browse files
Merge pull request steam-bell-92#237 from jyotish6699/fix/productivity-pet-input-validation
fix: improve input validation and retry flow in Productivity Pet
2 parents eeb4f1b + a712d2c commit 2c96062

1 file changed

Lines changed: 44 additions & 30 deletions

File tree

utilities/Productivity-Pet/Productivity-Pet.py

Lines changed: 44 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,46 +7,60 @@
77
user = input("➡️ Did you complete your tasks today? (yes/no): ").lower().strip()
88

99
if user in ["yes", "yeah", "yep"]:
10+
while True:
11+
count = input("📝 How many tasks were in your list? ").strip()
1012

11-
count = input("📝 How many tasks were in your list? ").strip()
13+
if not count.isdigit() or int(count) <= 0:
14+
print("⚠️ Please enter a valid number.\n")
15+
continue
1216

13-
if not count.isdigit() or int(count) <= 0:
14-
print("⚠️ Please enter a valid number.\n")
15-
continue
17+
count = int(count)
18+
tasks = []
19+
for i in range(count):
1620

17-
count = int(count)
18-
tasks = []
19-
for i in range(count):
20-
task = input(f" Task {i+1}: ")
21-
tasks.append(task)
21+
while True:
22+
task = input(f" Task {i+1}: ").strip()
2223

23-
done = input("✅ How many did you complete? ").strip()
24+
if not task:
25+
print("⚠️ Task name cannot be empty.")
26+
continue
2427

25-
if not done.isdigit():
26-
print("⚠️ Please enter a valid number.\n")
27-
continue
28+
tasks.append(task)
29+
break
30+
31+
while True:
2832

29-
done = int(done)
33+
done = input("✅ How many did you complete? ").strip()
3034

31-
if done < 0 or done > count:
32-
print("⚠️ That doesn't seem right. Try again.\n")
33-
continue
35+
if not done.isdigit():
36+
print("⚠️ Please enter a valid number.\n")
37+
continue
3438

35-
percentage = (done / count) * 100
36-
print(f"\n📊 Progress: {percentage:.1f}%")
39+
done = int(done)
3740

38-
pets = ["🐦", "🐧", "🦇", "🦤", "🦆", "🦅"]
39-
pet = random.choice(pets)
41+
if done < 0 or done > count:
42+
print("⚠️ That doesn't seem right. Try again.\n")
43+
continue
4044

41-
if percentage < 50:
42-
print("😔 The pet didn't hatch. Current stage: 🥚")
43-
print("💡 Try completing more tasks tomorrow!\n")
44-
elif percentage < 80:
45-
print("🐣 Getting there! Current stage: 🐣")
46-
print("💪 Almost hatched — keep going!\n")
47-
else:
48-
print(f"🎉 Congratulations! Your pet hatched: {pet}")
49-
print("🏆 Amazing work today!\n")
45+
break
46+
47+
percentage = (done / count) * 100
48+
print(f"\n📊 Progress: {percentage:.1f}%")
49+
50+
pets = ["🐦", "🐧", "🦇", "🦤", "🦆", "🦅"]
51+
pet = random.choice(pets)
52+
53+
if percentage < 50:
54+
print("😔 The pet didn't hatch. Current stage: 🥚")
55+
print("💡 Try completing more tasks tomorrow!\n")
56+
elif percentage < 80:
57+
print("🐣 Getting there! Current stage: 🐣")
58+
print("💪 Almost hatched — keep going!\n")
59+
else:
60+
print(f"🎉 Congratulations! Your pet hatched: {pet}")
61+
print("🏆 Amazing work today!\n")
62+
63+
break
5064

5165
elif user in ["no", "nope", "nah"]:
5266
print("💬 No worries! Come back when you're done.\n")

0 commit comments

Comments
 (0)