|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#p3_1.py
temp=input("猜猜我心里的数字")
guess=int(temp)
while guess==1:
if guess>1:
print("大了")
else:
print("小了")
temp=input("请再尝试吧:")
guess=int(temp)
print("你是我肚子的蛔虫")
这个while guess==1 循环的是什么为什么输入1的时候反而告诉我小了?
#p3_1.py
temp=input("猜猜我心里的数字")
guess=int(temp)
while guess!=1:
if guess>1:
print("大了")
else:
print("小了")
temp=input("请再尝试吧:")
guess=int(temp)
print("你是我肚子的蛔虫")
这个while guess!=就可以正常的循环
为什么呢?他们这个分别循环了什么?
本帖最后由 sfqxx 于 2023-3-3 17:54 编辑
因为没有进循环
改进代码: - temp=input("猜猜我心里的数字")
- guess=int(temp)
- while guess==1:
- if guess>1:
- print("大了")
- elif guess<1:
- print("小了")
- else:
- print("你是我肚子里的蛔虫")
- break#退出循环
- temp=input("请再尝试吧:")
- guess=int(temp)
复制代码
第二个问题,没有进循环就直接print那条语句了
|
|