首先说明你代码的不足之处:
0.temp=input() guess = int(temp1) 这里itemp是空字符串啊,所以会报错!
1. 第一个while循环不够简洁,而且 "猜了那么多次,估计就你猜不准了,好了好了,不猜了。“这个语句在第五次猜得时候如果guess》6就不会出现了。
我把代码贴出来,你仔细看看注释吧。
- times = 5
- secret = 6
- print("······```邪恶内心了解程度```······")
- temp1 = input("猜猜我一个月去健身房多少次啊:") #这里的input()函数这样写。
- guess = -1 #赋予guess一个初始值,保证进入while循环
- while (guess != secret) and (times >0):
- guess = int(temp1)
- times = times-1
- if guess == secret:
- print("我去,你个猪头不会跟踪我吧,这么了解我。")
- break
- elif (guess > secret) and (times>0): #这里用elif语句来写会非常简洁,但是条件改变一下
- print("哦呦,你他妈猜的这么多,我没你那么叼的。")
- temp1=input("你给老子重新去猜")
- elif (guess < secret) and (times>0): #这里的条件也要改变
- print("我心里还想多去几次呢。")
- temp1=input("朋友啊,多猜点嘛") #这里需要重新给temp1赋值,因为我把你下面的删除了
- elif times==0:
- print("猜了那么多次,估计就你猜不准了,好了好了,不猜了。")
-
- while guess != secret and times == 0:
- temp2 = input("想知道正确答案吗, 输入6就可以晓得答案喽:")
- answer = int(temp2)
- if answer == 6:
- print(secret)
- break
- else:
- print("滚!")
- print("再给你一次重新打数字的机会。")
- print("Game Over!!")
- print("No more guessing!")
复制代码
这样整体就比较简洁了,希望你能看一下哪里不一样
