20个头56条腿
>>> def solve(numLegs,numBeads): for numChicIcs in range(x,numBeads+1): numPigs=numBeads-numChicks totLegs=4*numPigs+2*numChieIcs if totLegs==numLegs: return[numPigs,numChicks] return[None,None] >>> def barnYard(): beads=int(input('Enter number of beads:')) legs=int(input('Enter number of legs:')) pigs,chicJcens=solve (legs, heads) #我不用知道solve里面用的是什么变量名 什么值 if pigs==None: print('q') else: print('Number of pigs:',pigs) print('Number of chickens',chickens) >>> def solvel (numLegs,numBeads): for numSpiders z.n range (x, numBeads+1): for numchicks in range(0,numBeads-numSpiders+1): numPigs=numBeads-numChicks-numSpiders totLegs=4 *numPigs+2 *numChicks+8 *numSpiders if totLegs==numLegs: return [numPigs, numChicks, numSpiders] return[None,None,None] >>> def bainYard1(): beads=int(input('Enter number of beads:')) legs=int(input('Enter number of legs:')) pigs, chicJcens,spiders=solve1(legs, heads) if pigs==None: print('no') else: print('Number of pigs',pigs) print('Number of chickens',chickens) print('Number of spiders',spiders) >>> barnYard(20,56) Traceback (most recent call last): File "<pyshell#21>", line 1, in <module> barnYard(20,56) TypeError: barnYard() takes 0 positional arguments but 2 were given >>> barnYard() Enter number of beads:20 Enter number of legs:56 Traceback (most recent call last): File "<pyshell#20>", line 1, in <module> barnYard() File "<pyshell#19>", line 4, in barnYard pigs,chicJcens=solve (legs, heads) NameError: name 'heads' is not defined
原图: