本篇文章主要讲述Python语言之解析猜字游戏,希望阅读本篇文章以后大家有所收获,帮助大家对相关内容的理解更加深入。
# 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')
本文由职坐标整理发布,学习更多的相关知识,请关注职坐标IT知识库!