1. Guess the number of small games
#!/usr/bin/python#-*-coding:utf-8-*-ImportRandomPrint "-------------------------------------"Print "Welcome to the guessing number games written by Aniuzaixian"Print "+++++ Please read the rules of the game +++++"s= Int (Random.uniform (1,100))Print """Game rules: 1. Please enter any integer between 1-100 (excluding 100),/2. Enter 0, and go back to the game! """Print "------------------------------------"name= Raw_input ("Please enter your name:")Print "Welcome to%s accept the challenge! "%Namem=-1 whiles! =M:str=raw_input ("Please enter an integer:") if(Str.isdigit ()): M=int (str)ifM >S:Print "big guess." Continue elifm = =0:Print "Welcome to try again next time" Break elifM <S:Print "small guess." Continue Else: Print "Please enter a number between 1-100 and not contain any other strings" ContinueElse: Print "%s That's great, guess right."%name
2. Scissors Mini-game
#!/usr/bin/env python#-*-coding:utf-8-*-ImportRandomPrint "Welcome to Aniuzaixian scissors Game software! "Print """Please read the game rules: 1. Please enter "stone", "scissors", "cloth" in any one of 2. Enter end to end the game!"""name=raw_input ("Please enter your name:")Print "Welcome to%s Scissors"%namecom=0per=0draw=0 whiletrue:s=int (Random.randint (1,3)) Computer="a computer punch ." if(s==1): Computer="Scissors" elif(s==2): Computer="Stone" Else: Computer="cloth" Person=raw_input ("please take a punch:") List=["Stone","Scissors","cloth"] if(PersoninchList and(Person! ="End"): if(Computer = =Person ):Print "it's a tie."Draw+=1Continue elif(computer=="Stone" andperson=="Scissors")or(computer=="Scissors" andperson=="cloth")or(computer=="cloth" andperson=="Stone"): Print "the computer won."com+=1Else: Print "%s won."%name per+=1elif(Person not inchList and(Person! ="End"): Print "you entered the wrong, please re-enter!" Continue Else: Sum= COM + per +DrawPrint "this game,%s total scissors%d times, win punch%d times, lose boxing%d times, draw a tie%d times"%(Name,sum,per,com,draw)Print "Welcome to%s play again next time!"%name Break
Python implementation guess numbers and scissors games