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