# 对头的数量进行有效性判断
while True:
head = int(input("鸡和兔的头数和:"))
if head>0:
break
else:
print("输入头数有误,请重新输入!")
# 对脚的数量进行有效性判断while True:
foot = int(input("鸡和兔的脚数和:"))
if foot>=head*2 and foot<=head*4:
break
else:
print("输入脚数有误,请重新输入!")
# 鸡的个数ji = 0
while ji<=head:
# 兔的个数tu = head - ji
if foot==ji*2+tu*4:
print("鸡有{}只,兔有{}只".format(ji,tu))
break
ji+=1
print("程序结束!")