zoukankan      html  css  js  c++  java
  • 竞猜游戏小玩

     1 # -*- coding:utf-8 -*-
     2 
     3 import random
     4 
     5 go =1
     6 while go == 1:
     7     num_start = int(raw_input('请输入开始的数字:'))
     8     num_end = int(raw_input('请输入结束的数字:'))
     9     f = int(raw_input('请输入循环的次数:'))
    10     pk = int(raw_input('pk的次数:'))
    11     userdict = {}
    12 
    13     def host(num_start,num_end):
    14         rand = random.randint(num_start,num_end)
    15         return rand
    16 
    17     for time in range(pk):
    18         a = 0
    19         rand = host(num_start, num_end)
    20         print "开始第", time + 1, ""
    21         for i in range(f):
    22             user = raw_input("请输入名字:")
    23             if not (user in userdict):
    24                 userdict[user] = 0
    25             guess = int(raw_input("请输入数字:"))
    26             if guess == rand:
    27                 print "您赢了!"
    28                 a = 1
    29                 if user in userdict:
    30                     userdict[user] += 1
    31                     break
    32             elif guess > rand:
    33                 print ("大于随机数。")
    34             else:
    35                 print "小于随机数。"
    36             print "这轮你还有",(f-i-1),"次机会。"
    37     if a != 0:
    38         break
    39         if a == 0:
    40             print ("你的数次用完了。")
    41             print "正确答案为", rand
    42     go = int(raw_input("继续请输入1,结束请输入0。"))
    43 
    44 def rank(dict):
    45     dict2 = sorted(dict.items(), key=lambda asd: asd[1], reverse=True)  # 给字典排序,reverse=True 表示升序
    46     # print dict2
    47     print("----------排行榜------------")
    48     for key in dict2:
    49         print(key[0] + "猜对了" + str(key[1]) + "")
    50     print("----------------------------")
    51 
    52 if __name__ == "__main__":
    53     rank(userdict)
  • 相关阅读:
    Boost Started on Windows
    7-Zip
    代码的命名规则
    基础扫盲:YEAR关键字 IN操作符
    基础扫盲:INSERT INTO 和 SELECT 结合使用
    知识盲点:存在外键的的表,在插入数据时应该如何操作?
    SQL Identity函数
    SQL 中DateName()函数及DatePart()函数
    OS开发多线程篇—GCD介绍
    经典SQL语句大全
  • 原文地址:https://www.cnblogs.com/panisme/p/8227786.html
Copyright © 2011-2022 走看看