The implementation of the Python Basics Tutorial stone scissors Cloth Game Example _python

Source: Internet
Author: User

Here's the rule. You and your opponent, at the same time to make specific gestures, must be the following gestures: stone, scissors, cloth. Winners from
In the following rule, the rule itself is a paradox.
(a) cloth-covered stones.
(b) Rock-breaking scissors,
(c) Scissors cut rags. In your computer version, the user enters her/his options, the computer is looking for a random option, and then you
Program to decide a winner or a tie. Note: The best algorithm is to use the IF statement as little as possible

Copy Code code as follows:

#coding: Utf-8

Import Random
Guess_list = ["Stone", "scissors", "cloth"]
Guize = [["Cloth", "stone"],["stone", "Scissors"],["scissors", "cloth"]]

While True:
Computer = Random.choice (guess_list)
People = input (' Please enter: stone, scissors, cloth \ n '). Strip ()

If people not in Guess_list:
People = input (' re-Please enter: stone, scissors, cloth \ n '). Strip ()
Continue
if computer = = People:
Print ("Tie, play again!") ")

elif [Computer,people] in guize:
Print ("Computer wins!") ")
Else
Print ("People win!") ")
Break

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.