Python basic actual combat-guess the age game

It takes 2 minutes to read this article

Python basic actual combat-guess the age game

  1. Given an age, the user can guess the age three times
  2. Guess the age correctly, let users choose two rewards
  3. Users can withdraw after choosing two rewards
age =18  #answer
count =0  #Game control
prize_dict ={0:'Ragdoll',1:'Transformers',2:'Ultraman',3:'<Python from entry to giving up>'}

# Core code
while count <3:
 inp_age =input('Please enter your age>>>')  #Interact with the user

 # Determine whether the user is harassing(Super class: Determine whether the user input is a number)if not inp_age.isdigit():print('Stupid,Your age is wrong')continue

 inp_age_int =int(inp_age)

 # Core logic,Judging age
 if inp_age_int == age:print('Got it right')print(prize_dict)  #Print prizes

  # Get two prizes
  for i inrange(2):
   prize_choice =input('Please enter the prize you want,If you don&#39;t want,Then enter"n"drop out!!!')  #Interact with users to get prizes

   # Determine whether a prize is needed
   if prize_choice !='n':print(f'Congratulations on your prize: {prize_dict[int(prize_choice)]}')else:breakbreak

 elif inp_age_int < age:print('Guessed')else:print('Guess big')

 count +=1  #Play a game successfully

 if count !=3:continue

 again_choice =input('Whether to continue the game,Please enter"Y",Otherwise, any key will exit directly.')  #Whether to interact again

 # Judge whether to continue
 if again_choice =='Y':
  count =0

operation result:

Please enter your age>>>18
Got it right
{0:' Ragdoll',1:'Transformers',2:'Ultraman',3:'<Python from entry to giving up>'}
Please enter the prize you want,If you don&#39;t want,Then enter"n"drop out!!!0
Congratulations on your prize:Ragdoll
Please enter the prize you want,If you don&#39;t want,Then enter"n"drop out!!!1
Congratulations on your prize:Transformers

Recommended Posts

Python basic actual combat-guess the age game
python guess the word game
Python realizes the guessing game
Python implements the brick-and-mortar game
Python simply implements the snake game
Python implements the actual banking system
Python solves the Tower of Hanoi game
Python basic syntax (1)
Python3 basic syntax
Python implements the source code of the snake game
How about learning python at the age of 27?
Python basic summary
2.1 The Python Interpreter (python interpreter)
Python basic operators
Python writes the game implementation of fishing master
Use python to realize the aircraft war game
Realize the tank battle game with Python | Dry Post
Realize the tank battle game with Python | Dry Post
Python implements tic-tac-toe game
Python implements tic-tac-toe game
Python function basic learning
Python, PyGame game project
Python implements Tetris game
Python implements minesweeper game
python_ crawler basic learning
Python basic data types
Basic syntax of Python
Basic knowledge of Python (1)
Consolidate the Python foundation (2)
Python basic data types
Python basic syntax iteration
Python implements guessing game