Getting started with Python--Rock and Scissor program

Source: Internet
Author: User

Overview:

If you and I are a programmer with other languages, then I think this little program is a small case for you. As I beginner python, first take this familiar with the grammar, it is no longer used to all the love of the Hello World.


Flow chart:



The code is as follows:

Import random# define a function for Get winner# 1:scissor# 2:stone# 3:clothdef get_winner (You, ME): if you = = Me: return 0 if you = = 1:if me = 2:return-1 Else:return 1 if you = = 2 : if me = = 1:return 1 else:return-1 If you = = 3:if me = = 2:r Eturn 1 else:return-1# Define a function for Get Label for fingerdef get_lable (finger): if finger = = 1:return "Scissor" elif finger = = 2:return "Stone" Else:return "Cloth" you = Raw_input ("You     R Finger is: ") while int (you) > 0:you = Int (you)% 3 if you = = 0:you = 3 me = Random.randint (1, 3)        Print "Your finger is%s and my finger are%s"% (get_lable (you), get_lable (me)) result = Get_winner (you, ME)    if result = = -1:print "I Win."    elif result = = 1:print "You Win."        Else:print "No winner." you = Raw_input("Your Finger is:") print "END" 


Getting started with Python--Rock and Scissor program

Related Article

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.