004小甲鱼改进的的第一个游戏
请问大佬,如何将第一次数字猜测的答案也有提示大或是小,用什么方法啊,谢谢!!!!import random
times = 3
secret = random.randint(1,15)
str_1 = "1 2 3"
str_2 = "a v b"
str_3 = "1 2 3 a v b"
print(str_1.isdigit())
print("-----giao-----")
temp = input("猜一下我心里想的数字是几")
guess = int(temp)
while guess != secret and times > 0:
temp = input("错!!!!!!!!!!再来")
while not temp. isdigit():
temp = input("数字。。。。。")
guess = int(temp)
times = times-1
if guess == secret:
print("我擦6")
print("滚吧a你")
else:
if guess > secret:
print("大了")
else:
print("小了")
print("拜拜")
改下位置即可,多加了if 是当 times == 0 的时候不在对用户进行输入
你前面代码有部分没什么意义,可以省略
import random
times = 3
secret = random.randint(1,15)
print("-----giao-----")
temp = input("猜一下我心里想的数字是几")
while not temp.isdigit():
temp = input("数字。。。。。")
guess = int(temp)
while guess != secret and times > 0:
while not temp.isdigit():
temp = input("数字。。。。。")
guess = int(temp)
times = times-1
if guess == secret:
print("我擦6")
print("滚吧a你")
else:
if guess > secret:
print("错啦,大了")
else:
print("错啦,小了")
if times != 0:
temp = input("猜一下我心里想的数字是几")
print("拜拜") import random
times = 3
secret = random . randint(1 , 15)
print("-----giao-----")
for x in range(times , 0 , -1):
while True:
temp = input("猜一下我心里想的数字是几 : ") . strip()
if temp . isdigit() :
break
else:
print("数字。。。。。\n")
guess = int(temp)
if guess == secret:
print("我擦6")
print("滚吧a你\n")
break
else:
if guess > secret:
print("大了\n")
else:
print("小了\n")
else:
print("太遗憾了!\n")
print("拜拜") 本帖最后由 谢小猪的husband 于 2020-11-10 12:35 编辑
新手玩法。。。望大神指点
import random
real= random.randint(1,10)
times=2
print('------猜猜我心里的数字-------')
temp= input('请输入1-10之间的整数:')
guess=int(temp)
if guess==real:
print('很棒,你跟我心灵相通')
print('游戏结束!')
elif guess<real:
print('憨憨猜错啦,往大了猜!')
else :
print('憨憨猜错啦,往小了猜!')
while guess!= real and times>0:
temp= input('还有'+str(int(times))+'次机会,请重新输入:')
guess=int(temp)
if guess==real:
print('很棒,你跟我心灵相通')
print('游戏结束!')
elif guess<real:
print('憨憨猜错啦,往大了猜!')
else :
print('憨憨猜错啦,往小了猜!')
times=times-1
if times==0:
print('错太多啦,游戏结束')
print('GG')
页:
[1]