Initial commit

This commit is contained in:
2025-09-09 12:44:53 +03:00
commit c79a365a72
6 changed files with 473 additions and 0 deletions

56
guess_number.py Normal file
View File

@ -0,0 +1,56 @@
#!/usr/bin/env python3
def generate_number_groups(max_number):
"""Generate groups of numbers based on binary representation."""
groups = []
bit_position = 0
while (1 << bit_position) <= max_number:
group = []
for num in range(1, max_number + 1):
if num & (1 << bit_position):
group.append(num)
groups.append(group)
bit_position += 1
return groups
def guess_number():
print("🎯 Number Guessing Game")
print("Think of a number between 1 and 63")
print("I'll show you groups of numbers, tell me if your number is in each group")
print("-" * 50)
max_number = 63
groups = generate_number_groups(max_number)
result = 0
for i, group in enumerate(groups):
print(f"\nGroup {i + 1}:")
print("Numbers:", " ".join(map(str, group)))
while True:
answer = input("Is your number in this group? (y/n): ").lower().strip()
if answer in ['y', 'yes', '1']:
result += (1 << i)
break
elif answer in ['n', 'no', '0']:
break
else:
print("Please answer 'y' for yes or 'n' for no")
print(f"\n🎉 Your number is: {result}")
return result
def main():
while True:
guess_number()
play_again = input("\nDo you want to play again? (y/n): ").lower().strip()
if play_again not in ['y', 'yes', '1']:
print("Thanks for playing! 👋")
break
print()
if __name__ == "__main__":
main()