learn Python Before that, let's practice with some simple games , These three games are more complicated than one , Novices are advised to take their time :
1. the finger-guessing game :
import random # Import random module num = 1 yin_num = 0 shu_num = 0 while num <= 3: if
shu_num == 2 or yin_num == 2: break user = int(input(' Please punch 0( stone ) 1( scissors ) 2( cloth )'))
if user > 2: print(' Cannot be greater than 2 Value of ') else: data = [' stone ', ' scissors ', ' cloth '] com =
random.randint(0, 2) print(" What did you say {}, What's wrong with the computer {}".format(data[user], data[com])) if
user == com: print(' it ends in a draw ') continue elif (user == 0 and com == 1) or (user == 1
and com == 2) or (user == 2 and com == 0): print(' You win ') yin_num += 1 else:
print(' You lost ') shu_num += 1 num += 1
2. Digital bomb :
import random import time bomb = random.randint(1, 99) print(bomb) start = 0
end = 99 while 1 == 1: people = int(input(' Please enter {} reach {} Number between :'.format(start, end)))
if people > bomb: print(' Big ') end = people elif people < bomb: print(' Small ')
start = people else: print('BOOM!!!') break
print(' Wait for the computer to input {} reach {} Number between :'.format(start, end)) time.sleep(1) com =
random.randint(start + 1, end - 1) print(' Computer input :{}'.format(com)) if com > bomb:
print(' Big ') end = com elif com < bomb: print(' Small ') start = com else:
print('BOOM!!!') break
3. bet includes all the dice :
import time import random # Let users register name = input(' Please fill in the user name :') age =
input("{} Hello! , Please enter your age : ".format(name)) user_info = {'name': name, 'age':
int(age)} # User information user_properties = ['X 1-5'] # Used to store user props Default props properties = ['X3
(250G)', 'X1-5 (300G)'] # Prop list For display # According to user age Give different initial gold coins if 10 < user_info['age']
< 18: glod = 1000 elif 18 <= user_info['age'] <= 30: glod = 1500 else: glod =
500 user_info['glod'] = glod # Output relevant prompt information
print("{} Hello! , Welcome to this game , Your initial gold coin is :{}".format(user_info['name'], user_info['glod']))
print("\n") time.sleep(1) print(' Game Description '.center(50, '*')) print('*'.ljust(53),
'*') print('*', end='') print(" The computer rolls three dice at a time , Total points >=10 For big , Otherwise, it is small ".center(32), end='')
print('*') print('*'.ljust(53), '*') print('*' * 54) print("\n") # Start the game result
= input(' Start game yes or no : ') go = True if (result.lower() == 'yes'): while
go: dices = [] # Start throwing for i in range(0, 3): dices.append(random.randint(1, 6))
total = sum(dices) # Calculate sum user_input = input(' Please enter big OR small : ') # Waiting for user input
u_input = user_input.strip().lower() time.sleep(1) # Judge user input
print(' Dice points are :{}'.format(dices), end=' ') if (total >= 10 and u_input == 'big')
or (total < 10 and u_input == 'small'): print(' You won !!!') multi = 1 # multiple if
len(user_properties) > 0: # If the user has props Choose whether to use props use_pro = input(' Use props : ') if
use_pro.lower() == 'yes': use_pro = int(input(' Please choose which props to use {}
:'.format(user_properties))) use_pro -= 1 # Judge prop type if user_properties[use_pro]
== 'X 3': multi = 3 print(' Bonus turnover 3 times ') elif user_properties[use_pro] == 'X 1-5':
multi = random.randint(1, 5) print(' Bonus turnover {} times '.format(multi))
user_properties.remove(user_properties[use_pro]) # Delete Item user_info['glod'] +=
100 * multi; # Increase in amount else: print(' You lost !') user_info['glod'] -= 100; # error User gold minus
100 # Judge user gold coins Is it enough to play next time If not enough, exit the program if (user_info['glod'] <= 0):
print(' Your gold coins have been used up , Thank you for your visit ') break if user_info['glod'] % 1000 == 0: # User gold coins
yes 1000 The multiple of is Props can be purchased shop = input(' You have gold coins now :{}, Buy props yes or no:
'.format(user_info['glod'])) if shop.lower() == 'yes': good_num =
int(input(' Please select which props to purchase {}'.format(properties))) if good_num == 1:
user_properties.append('X 3') # Add props to users user_info['glod'] -= 250
print(' Purchase successful ! Consume gold coins 250') elif good_num == 2: user_properties.append('X 1-5') #
Add props to users user_info['glod'] -= 300 # User gold minus 300 print(' Purchase successful ! Consume gold coins 300') else:
print(' There is no such prop , You lost this opportunity ') else: # Always prompt Too annoying # conti = input(' You have gold coins now :{}, Continue to play ,yes
or no: '.format(user_info['glod'])) print(' You have gold coins now :{}
'.format(user_info['glod'])) else: print(' Welcome to play next time , bye !')

Technology