import easygui as g import random d=random.randint(0,10) while 1: g.msgbox("现在开始猜数字小游戏:") # num=int(g.enterbox(title='猜我心里在想哪个数字')) msg="我心里在想哪个数字" title='玩游戏' num=g.integerbox(msg,title,lowerbound=0,upperbound=99) if num==d: g.msgbox(…
""" 猜数字游戏(电脑给数字人猜) Author:罗万财 Date:2017-6-3 """ from random import randint you_answer=int(input('请输入:')) counter=0 x=1 y=100 is_correct=False while not is_correct: counter+=1 answer=randint(x,y) print(answer) if answer>you…
增加了按照对半找数的方法来计算最短几次就可以猜到随机数,决定到游戏结束共猜数的次数: from random import * import numpy as np from numpy import * from math import * #可以根据猜数据的范围来决定可以猜的次数 print('请输入游戏猜数的范围(Min Max)') Min=int(input()) Max=int(input()) A= linspace(Min,Max,Max) com=choice(A) #prin…
#Author:xiaoxiao age = 22 #标准正确答案 counter = 0 #计数器 for i in range(10): #循环10次 if counter < 3: guess_num = int(input('input your guess num:')) if guess_num == age: print('Congratulations! you got it.') break #跳出整个循环 elif guess_num > age: print('Think…