欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

python 猜字游戏

程序员文章站 2022-10-06 11:33:14
# coding=utf-8import randomprint("猜数字游戏开始\n")count = 0count1 = 0guessact = random.randint(5, 15)print("猜数提示:取值范围5-15,整数值\n")while 1 == 1: guess = int( ......

# coding=utf-8
import random
print("猜数字游戏开始\n")
count = 0
count1 = 0
guessact = random.randint(5, 15)
print("猜数提示:取值范围5-15,整数值\n")
while 1 == 1:
guess = int(input("请输入猜想数字: "))
count+=1
count1+=1
if guess == guessact:
print('恭喜你成功猜出\n')
break
if guess > guessact:
print('\n 数字偏大,请减小')
else:
print('\n 数字偏小,请增大')
if count1 == 5:
count1 = 0
print('\n 已经猜了5次,是否继续猜数,若结束请输入 y or y,否则请输入n or n \n')
c = input()
if c == 'y' or c == 'y':
print("\n很遗憾,退出游戏\n")
break
if c != 'n' or c != 'n':
while 1 == 1:
if c == 'n' or c == 'n':
break
print('\n警告:输入不正确,请重新输输入n or n \n')
c = input()

print('\n 是否需要系统更改猜测数字,若需要请输入 y or y,否则请输入n or n \n')
d = input()
if d == 'y' or d == 'y':
guessact = random.randint(5, 15)
elif d != 'n' or d != 'n':

while 1 == 1:
if d == 'n' or d == 'n':
break
d = input('\n警告:输入不正确,请重新输输入n or n; ')

print("\n 总共已猜次数:\t", count)
print('\n')