Python 3.4.3 (v3.4.3:9b73fIc3e601, Feb 24 2015, 22:43:06) [MSC v.1600 32 bit (In tel)] on Win32 Type "copyright", "credits" or "license()" for more information. »> def solve (numLegs,numBeads) SyntaxError: invalid syntax »> def solve(numLegs,numBeads): for numChicIcs in range(x,numBeads+1): numP i g s=numB e a ds - numCh i c ks totLegs=4 *numPigs+2 *numChieIcs if totLegs==numLegs: return[numPigs,numChicks] return[None,None] »> def bainYard() : beads=int(input(‘Enter number of beads:‘)) legs=int(input(‘Enter number of legs:‘)) pigs, chicJcens=solve (legs, heads) if pigs=None: SyntaxError: invalid syntax »> def bainYard() : beads=int(input(‘Enter number of beads:‘)) legs=int(input(‘Enter number of legs:‘)) pigs, chicJcens=solve (legs, heads) 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 iaj range(0,numBeads-numSpiders+1): SyntaxError: invalid syntax »> def solvel (numLegs,numBeads) : for numSpiders z.n range (x, numBeads+1) : for numchicks in range(0,numBeads-numSpiders+1): numP i g s=numB e a ds - numCh i c ks - numSp i de r s totLegs=4 *numPigs+2 *numChicks+8 *numSpiders if totLegs==numLegs: return [numPigs, numChicks, numSpiders] return[None,None,None] »>
时间: 2024-10-10 07:11:48