Python求助
请问要求二怎么实现,代码还有什么地方可以修改的 贴代码文本难道比贴图片困难吗? 不要发只发图片,你不要指望每个人都有精力去重新敲一遍你的代码再回答你{:10_250:} 在while循环外再套一个while True,然后内层while循环结束后,在外层循环里进行判定 hrp 发表于 2021-2-1 22:40不要发只发图片,你不要指望每个人都有精力去重新敲一遍你的代码再回答你
不好意思
import random
count = 0
while count < 3:
count += 1
robot = random.randint(1,100)
user_print = int(input("请您猜猜张三的年龄:"))
if user_print == robot:
print("恭喜您猜对了,我们可真有默契呢!")
exit()
elif user_print > robot:
print("猜大了,请在猜一次!还剩下",3-count,"次机会")
else:
print("猜小了,请在猜一次!还剩下",3-count,"次机会") import random
count = 3
# 密码不能在循环里,否则循环一次重新生成一个密码,能猜对可以买彩票了
num = random.randint(1, 100)
while count:
guess = int(input('请猜猜年龄(整数):'))
if guess == num:
print('恭喜猜对了!')
break
elif guess > num and count > 0:
print('猜大了!',end='')
else:
print('猜小了!', end='')
count -= 1
if not count:
flag = input('机会用光了,继续游戏吗?Y/N:')
if flag in 'yY':
count = 3
# 如果所谓的还想玩是重新生成密码则这样,如果不重新生成密码则把下面这行删除
num = random.randint(1, 100)
continue
elif flag in 'nN':
break
else:
print('请再猜一次,还剩下%d次机会!' % count) import random
robot = random.randint(1,100)
count = 0
while True:
if count == 3:
switch = input("已经错误三次,是否继续? 【 Y / N 】:")
if switch in ["y","Y"]:
print("重新获得三次机会\n","-"*20)
count = 0
continue
elif switch in ["n","N"]:
print("您选择了退出")
break
else:
print("输入错误指令请重新输入")
continue
user_print = int(input("请您猜猜张三的年龄:"))
count += 1
if user_print == robot:
print("恭喜您猜对了,我们可真有默契呢!")
break
elif user_print > robot:
print("猜大了,请在猜一次!还剩下",3-count,"次机会")
else:
print("猜小了,请在猜一次!还剩下",3-count,"次机会")
print("已退出") import random
robot = random.randint(1, 100)
flag = 0#设置结束的标志
def TreeTime ():
""""玩三次"""
count = 0
while count < 3:
count += 1
user_print = int(input("请您猜猜张三的年龄:"))
if user_print == robot:
print("恭喜您猜对了,我们可真有默契呢!")
global flag
flag = 1
exit()
elif user_print > robot:
print("猜大了,请在猜一次!还剩下",3-count,"次机会")
else:
print("猜小了,请在猜一次!还剩下",3-count,"次机会")
while flag == 0:
TreeTime()
if flag == 0:
answer = input("是否还想玩,是用Y/y表示;回答N/n直接退出:")
if answer =='N' or answer =='n':
exit()
页:
[1]