The implementation of basic Python tutorial stone scissors Cloth Game Example

Source: Internet
Author: User
Here are the rules. You and your opponent, at the same time make a specific gesture, must be the following gesture: stone, scissors, cloth. Victor from
In the following rules, the rule itself is a paradox.
(a) cloth-clad stones.
(b) The stone hit the scissors,
(c) Scissors cut the cloth. In your computer version, the user enters her/his options, the computer is looking for a random option, and then by you
Program to determine a winner or a tie. Note: The best algorithm is to use the IF statement as little as possible

Copy the 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 input: stone, scissors, cloth \ n '). Strip ()

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

elif [Computer,people] in guize:
Print ("Computer wins!" ")
Else
Print ("Man wins!" ")
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.