#! /usr/bin/env python
# coding:utf-8
import random
"""
Guesser number ,by wumi ,2017-07-22
"""
def main():
print "guess a number between 1 to 100,how many time you guessed it"
randNumber = random.randint(1,100)
#print randNumber
found = False
times= 0
while not found:
userGuess= input("Enter your guess:")
if randNumber==userGuess:
print "Congratulations.."
print "Guess times:" ,times+1
found = True
elif randNumber > userGuess:
print "Enter bigger"
times +=1
else:
print "Enter lower"
times += 1
if __name__ == '__main__':
main()
'''
guess a number between 1 to 100,how many time you guessed it
Enter your guess:50
Enter lower
Enter your guess:25
Enter lower
Enter your guess:17
Enter bigger
Enter your guess:20
Enter bigger
Enter your guess:23
Congratulations..
Guess times: 5
'''
转载于:https://www.cnblogs.com/TendToBigData/p/10501221.html