python编写石头剪刀布获胜法_石头、布、剪刀在数学上获胜

An easy way [for beginners] codehs rocks, paper and scissors

Long because its for beginners if u are advanced use the above code..

"""

Introduction - Imports, Instructions, Declaring Variables, Lists and Computer Choice

"""

# Imports

import time

time.sleep(2)

print "Hello !"

# Delays Response to 2 secs

time.sleep(2)

# Instructions

print "Are you ready to play Rock, Paper and Scissors with the Computer ? "

time.sleep(4)

# Asking if user is ready or not !! (Does Nothing whatever the User Answers)

yes_no = input("Are You Ready to play (Y/N) : ")

time.sleep(2)

print "Ready or Not, here we go !! "

time.sleep(2)

# Declaring Variables

win_user = 0

win_comp = 0

tie = 0

# Imports Random and Sys

import random

import sys

# Choices in a list

choices = ["Rock", "Paper", "Scissors"]

# Computer Choice - between choices [list]

comp_choice = random.choice(choices)

"""

User Input and Computer Input

"""

# Asks User for Rocks, Papers or Scissors

user_input = input("Rock, Paper or Scissors ? : ")

# User_input is now set to User_choice

user_choice = user_input

time.sleep(2)

# Prints what user entered

print "User entered : " + user_choice

time.sleep(2)

# Prints what computer entered

print "Computer entered : " + comp_choice

# Basic Gameplay

if user_choice == "Rock" and comp_choice == "Paper":

win_comp += 1

if user_choice == "Paper" and comp_choice == "Rock":

win_user += 1

if user_choice == "Scissors" and comp_choice == "Paper":

win_user += 1

if user_choice == "Paper" and comp_choice == "Scissors":

win_comp +=1

if user_choice == "Rock" and comp_choice == "Scissors":

win_user +=1

if user_choice == "Scissors" and comp_choice == "Rock":

win_comp +=1

if user_choice == "Rock" and comp_choice == "Rock":

tie +=1

if user_choice == "Paper" and comp_choice == "Paper":

tie +=1

if user_choice == "Scissors" and comp_choice == "Scissors":

tie +=1

"""

Ties, User Wins and Computer Wins and Conclusion

"""

time.sleep(2)

# Checks the amounts of ties, user wins and computer wins !!!

print "User Wins : " + str(win_user)

time.sleep(2)

print "Computer Wins : " + str(win_comp)

time.sleep(2)

print "Ties : " + str(tie)

time.sleep(2)

print "Thank You For Playing !!"

"""

Exit and Repeats

"""

time.sleep(2)

# Asks if User wants to exit or Not !!

ask_user = input("Do you want to exit (Y/N) : ")

# Exit is a variable which does nothing thus it exits the game

exit = 0

# If Y, then it will exit

if ask_user == "Y":

# Does nothing, except adding a 1 to exit

exit += 1

# Elif ask_user == "N", repeats everything again using the WHile loop

elif ask_user == "N":

# WHILE LOOP

while ask_user == "N":

win_user = 0

win_comp = 0

tie = 0

import time

import random

import sys

choices = ["Rock", "Paper", "Scissors"]

comp_choice = random.choice(choices)

time.sleep(2)

user_input = input("Rock, Papers or Scissors ? : ")

user_choice = user_input

time.sleep(2)

print "User entered : " + user_choice

time.sleep(2)

print "Computer entered : " + comp_choice

if user_choice == "Rock" and comp_choice == "Paper":

win_comp += 1

if user_choice == "Paper" and comp_choice == "Rock":

win_user += 1

if user_choice == "Scissors" and comp_choice == "Paper":

win_user += 1

if user_choice == "Paper" and comp_choice == "Scissors":

win_comp +=1

if user_choice == "Rock" and comp_choice == "Scissors":

win_user +=1

if user_choice == "Scissors" and comp_choice == "Rock":

win_comp +=1

if user_choice == "Rock" and comp_choice == "Rock":

tie +=1

if user_choice == "Paper" and comp_choice == "Paper":

tie +=1

if user_choice == "Scissors" and comp_choice == "Scissors":

tie +=1

time.sleep(2)

print "User Wins : " + str(win_user)

time.sleep(2)

print "Computer Wins : " + str(win_comp)

time.sleep(2)

print "Ties : " + str(tie)

time.sleep(2)

print "Thank You For Playing !!"

time.sleep(2)

ask_user = input("Do you want to exit (Y/N) : ")

if ask_user == "Y" or "Yes" or "y" or "yes":

break

else:

print "Wrong Input, Try again by restarting the program"

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值