Small Item - Age Guess Game

Posted by cheesemunger on Wed, 31 Jul 2019 04:02:05 +0200

This is a small project that needs to be previewed today. The rules are as follows.

  1. Given the age, the user can guess the age three times.
  2. Age guess right, let users choose two rewards
  3. Users can quit after choosing two rewards
age = 18  # Answer
count = 0  # Game Number Control
prize_dict = {0: 'Rag doll', 1: 'Transformers', 2: 'Ultraman', 3: '<Python From Initial to Abandoned>'}

while count < 3:
    age_of_user = input("Enter your guessed age:")
    if not age_of_user.isdigit():
        print("Please enter the digital brothers")
        continue
    age_of_user = int(age_of_user)
    if age_of_user == age:
        print("Congratulations. You guessed right. You have two opportunities to choose awards.,input'q'Sign out")
        prize_key = [0]*2
        k = 0
        while k < 2:
            print(prize_dict)
            choice = input("Enter the reward you want")
            if choice == 'q':
                count = 99
                break
            if not choice.isdigit():
                print("Please enter the digital brothers")
                continue
            choice = int(choice)
            if choice in prize_dict:
                print("You chose%s" % prize_dict[choice])
                prize_key[k] = choice
                k += 1
            else:
                print("Please enter 0-3")
                continue
        print("The awards you choose are:")
        if k:
            for i in range(2):
                print(" %s"%prize_dict[prize_key[i]])
    elif age_of_user < age:
        print("Guess the iron is too small. You still have it.%d Secondary Opportunities" % (2-count))
    else:
        print("Guess the big iron, you still have it.%d Secondary Opportunities" % (2-count))
    if count == 99:
        print("Don't reward you for being a real bull, bye-bye.")
        break
    if count == 2:
        print("No chance. Bye-bye.")
        break
    else:
        again = int(input("Do you want to continue, Tie Zi, you still have it?%d Second chance, exit by 0, continue by 1"%(2-count)))
        if again == 1:
            count += 1
        else:
            break;

In fact, there is nothing to say. I think some of the things that can be updated are to give users a list to display the prizes they have won, or how many prizes each has, so that the choice is more realistic.

And I think it's interesting to guess numbers. If someone can tell you whether your guess is bigger or smaller than the actual one, it's good to choose the middle number every time. For example, give a range of 0-100, guess 50 for the first time, 25 for the big one, 75 for the small one. Haha, that's the dichotomy.

But I think it can be extended. How many times can you guess the number within 100?

My guess is seven times, after all, 2 ^ 7 ^ > 100 > 2 ^ 6 ^...

Topics: PHP Python