zoukankan      html  css  js  c++  java
  • 猜拳游戏

    前几天看到这个题目,就在写,但是不是知道为什么老是出错,今天起来再一些了一遍测试就对了不知道为什么!

     1 #!/usr/bin/env python
     2 #coding:utf-8
     3 
     4 import random
     5 
     6 winrule = ['stone','scissors','cloth',]
     7 guize = [['cloth','stone'],['stone','scissors'],['scissors','cloth']]
     8 i = 0
     9 time = 3
    10 people_win_time = 0
    11 people_lost_time = 0
    12 while i < time:
    13              i += 1
    14              computer = random.choice(winrule)
    15              print computer
    16              people = raw_input('People select: ')
    17              if computer == people:
    18                           print 'draw'
    19              else:
    20                           if [computer,people] in guize:
    21                                        print 'Bad! YOU LOST!'
    22                                        people_lost_time += 1
    23                           else:
    24                                        print 'God! YOU WIN!'
    25                                        people_win_time += 1
    26 print 'people_win_time : %s,people_lost_time : %s' %(people_win_time,people_lost_time)
    27 if people_win_time > people_lost_time:
    28              print 'you win!'
    29 else:
    30              if people_win_time == people_lost_time:
    31                           print 'draw'
    32              else:
    33                           print 'you lost'

    还有没有解决的问题:

      1、如果出现了赢了的次数和输了的次数一样的话想重新再来一遍,或者输入exit直接退出不玩了,今天没有时间就没有写了

      2、如果输入的不是stone,scissors,cloth,则提示要输入stone,scissors,cloth。

  • 相关阅读:
    继承
    JAVA接口的继承与集合
    JAVA接口
    c++程序—敲桌子
    c++程序—水仙花数
    c++程序—while猜数字游戏
    c++程序—switch分支
    c++程序—三目运算符
    c++程序—if语句实践
    c++程序—选择结构
  • 原文地址:https://www.cnblogs.com/114811yayi/p/5441318.html
Copyright © 2011-2022 走看看