Guess the Number

原创 2016年08月28日 21:30:53

问题:点击打开链接 (练习二):

注释文档:

 1.程序询问是否想进行游戏:输入Yes

 2.程序产生随机数value

 3. 进入判断循环 , 输入数据guessNum 和 value产生对比,

 if(guessNum > value) print 'too high';

elif(guessNum < value) print 'too low' 

elif(guessNum == value) print 'correct'

发现相等时退出判断循环

# -*- coding: utf-8 -*-

import random

class Random(object):
    def __init__(self, _min, _max):
        self.min = _min
        self.max = _max
    def getValue(self):
        return random.randint(self.min, self.max) 

if __name__ == '__main__': 
    cnt = 0; flag = 0
    ins = Random(0, 100)   #取值范围为0-100
    while True:
        cnt = cnt+1
        while True:  
            if cnt == 1:              
                print 'Would you like to roll \\ (Yes or No)'  
            else :  
                print 'Would you like to roll again \\ (Yes or No)'  
            str = raw_input()  
            if str == 'Yes':  
                break  
            elif str == 'No':  
                flag = 1  
                break  
            else:  
                print 'Illegal input'  
        if flag == 1:
            break
        value = ins.getValue()
        while True:
             guessNum = int(raw_input())
             if guessNum == value:
                 print 'correct'
                 break
             elif guessNum > value:
                 print 'too high'
             elif guessNum < value:
                 print 'too low'


leetcode 375. Guess Number Higher or Lower II 解题小结

题目是这样子的,跟374很像: We are playing the Guess Game. The game is as follows: I pick a number from ...
  • adfsss
  • adfsss
  • 2016年07月19日 02:08
  • 2579

LeetCode 374. Guess Number Higher or Lower

We are playing the Guess Game. The game is as follows: I pick a number from 1 to n. You have to g...
  • y12345678904
  • y12345678904
  • 2016年07月13日 16:06
  • 1326

lintcode Guess Number Game(Java)

1.题目 We are playing the Guess Game. The game is as follows: I pick a number from 1 to n. You ha...
  • C_calary
  • C_calary
  • 2017年07月03日 10:32
  • 503

HDU 1562 Guess the number

Description Happy new year to everybody!  Now, I want you to guess a minimum number x betwwn 100...
  • jtjy568805874
  • jtjy568805874
  • 2016年08月03日 16:53
  • 390

杭电 HDU ACM 1562 Guess the number

Guess the number Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others...
  • lsgqjh
  • lsgqjh
  • 2015年04月06日 13:47
  • 557

[leetcode] 374. Guess Number Higher or Lower 解题报告

题目链接:https://leetcode.com/problems/guess-number-higher-or-lower/ We are playing the Guess Game....
  • qq508618087
  • qq508618087
  • 2016年07月16日 03:13
  • 2195

【Python】Python条件语句

Python条件语句是通过一条或多条语句的执行结果(True或者False)来决定执行的代码块。 可以通过下图来简单了解条件语句的执行过程: if语句 Python中if语句的一般形式如下所...
  • u014647208
  • u014647208
  • 2017年09月01日 10:57
  • 191

关于LeetCode中Guess Number Higher or Lower一题的理解

题目如下: We are playing the Guess Game. The game is as follows: I pick a number from 1 to n. You have...
  • zsy112371
  • zsy112371
  • 2016年09月08日 13:52
  • 704

374. Guess Number Higher or Lower [easy] (Python)

题目链接https://leetcode.com/problems/guess-number-higher-or-lower/题目原文 We are playing the Guess Game....
  • coder_orz
  • coder_orz
  • 2016年07月26日 19:49
  • 1376

莱斯大学Python课程Mini-project # 2 - "Guess the number" game

要求:https://class.coursera.org/interactivepython-004/human_grading/view/courses/972072/assessments/29...
  • u013581823
  • u013581823
  • 2014年04月19日 18:17
  • 1193
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:Guess the Number
举报原因:
原因补充:

(最多只允许输入30个字)