一、一个笼子里关了若干只兔子和鸡(兔子有4只腿,鸡有2只腿),则笼子里面至多有多少只动物,至少有多少只动物

鸡兔同笼 Python 第1张

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。
n = eval(input())
l = list()
for k in range(n):
    a = int(input())
    if (a%2) != 0:
        min = max = 0
    else:
        j = int(a/4)
        i = a%4
        m = int(i/2)
        min = m+j
        max = int(a/2)
    l += [(min,max)]
for b,c in l:
    print(b,c,end='')
    print(end='\n')

 

二、用户在同一行输入两个整数。代表头和脚的数量,计算笼子里有多少只鸡和兔子

鸡兔同笼 Python 第2张

 

head,foot = map(int,input().split())
if int(foot-head*2)/2==(foot-head*2)/2 and foot-head*2 > 0 and head>=0 and foot>=0:
    print(int(head-(foot-head*2)/2), int((foot-head*2)/2))
else:
    print('Data Error!')

  

扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄