关于猜生成随机数
为什么会出现数字大于7但是又小于8的情况呀源代码:import random#随机模块
counts = 5
ans = random.randint(1,10)
while counts > 0:
temp = input("please write your score:")
guess = int(temp)
if guess == ans:
print("you are so good!")
break
else:
if guess < 8 :
print("too small")
else:
print("too big")
counts = counts - 1
print(r"for still here I'll be") 逻辑不对,你不得和ans比较,为啥要和8比较??? 很简单,当答案为6的时候
8==6(错,ans=6)
8<8 (错,所以提示更小)
7<8 (对,所以更小)
你应该把
if guess < 8 :
改为
if guess < ans : wp231957 发表于 2022-3-9 10:05
逻辑不对,你不得和ans比较,为啥要和8比较???
傻掉了555 cct 发表于 2022-3-9 10:09
很简单,当答案为6的时候
8==6(错,ans=6)
8
呜呜呜Thanks♪(・ω・)ノ
页:
[1]