Python implementation guess numbers and scissors games

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.