一、一個籠子里關了若干只兔子和雞(兔子有4只腿,雞有2只腿),則籠子里面至多有多少只動物,至少有多少只動物

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')
二、用戶在同一行輸入兩個整數,代表頭和腳的數量,計算籠子里有多少只雞和兔子

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!')
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/158295.html
標籤:Python
上一篇:青蛙跳臺階
