python循环设置循环次数
print('=============111==========')count=1temp=input("猜猜:")guess=int(temp)whileguess!...
print('=============111==========')
count = 1
temp = input("猜猜:")
guess = int(temp)
while guess !=8 and count <3 :
temp = input("错了错了:")
guess = int(temp)
if guess == 8:
print('对')
else:
if guess > 8:
print ("大了")
else:
print("小了")
guess = int(temp)
count +=1
print("不玩了")
猜的数字必须是10以内的,超过10的数字就对所循环次数的设置没有作用了,请问下是怎么回事? 展开
count = 1
temp = input("猜猜:")
guess = int(temp)
while guess !=8 and count <3 :
temp = input("错了错了:")
guess = int(temp)
if guess == 8:
print('对')
else:
if guess > 8:
print ("大了")
else:
print("小了")
guess = int(temp)
count +=1
print("不玩了")
猜的数字必须是10以内的,超过10的数字就对所循环次数的设置没有作用了,请问下是怎么回事? 展开
3个回答
展开全部
##左边每个=表示一个空格
print('=============111==========')
count = 1
temp = input("猜猜:")
guess = int(temp)
while guess !=8 and count <3 :
====temp = input("错了错了:")
====guess = int(temp)
====if guess == 8:
========print('对')
========break
====else:
========if guess > 8:
============print ("大了")
========else:
============print("小了")
##注意count +=1是怎样缩进的
========count +=1
print("不玩了")
print('=============111==========')
count = 1
temp = input("猜猜:")
guess = int(temp)
while guess !=8 and count <3 :
====temp = input("错了错了:")
====guess = int(temp)
====if guess == 8:
========print('对')
========break
====else:
========if guess > 8:
============print ("大了")
========else:
============print("小了")
##注意count +=1是怎样缩进的
========count +=1
print("不玩了")
2019-10-09
展开全部
代码判断不对,在大于8的判断的地方没有ciunt=+1
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
嵌套可以实现这样的做法
lists=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]
def rl(lists, n):
for i in lists:
if i%(1+n)==0:
lists.remove(i)
print(n, lists)
if n > 1:
rl(lists[:], n-1)
rl(lists, 3)
可是为什么不简化一下
lists=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]
lists1=lists[:]
for n in range(3):
for i in lists1:
if i%(2+n)==0:
lists1.remove(i)
print(lists1)
lists=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]
def rl(lists, n):
for i in lists:
if i%(1+n)==0:
lists.remove(i)
print(n, lists)
if n > 1:
rl(lists[:], n-1)
rl(lists, 3)
可是为什么不简化一下
lists=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]
lists1=lists[:]
for n in range(3):
for i in lists1:
if i%(2+n)==0:
lists1.remove(i)
print(lists1)
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询