Could someone clarify how we get all the possible solutions for the barnyard problem in handout 4? Also, why do we type convert numPigs and numChicks in the three 'print' statements but not type convert numSpiders?
what do you mean by barnyard i cant locate the word in handout 4
barnyard() was the ‘def’ function to call the solve() function and printout the number of pigs and chickens and spiders in the barnyard in the two previous examples where you are given the number of heads and legs. In those two cases only one output was given out of several other possible outcomes. solve2() allows for all the possible combinations to be printed out in the interpreter. I’m not sure how that was achieved. Probably has to do with the ‘print’ statements in that block. Also confusing is that they type convert numChicks and numPigs but not numSpiders..
by handout 4 i mean the handout given in lecture 4
2008 class i assume. Don't understand what you are asking. I don't see the word 'convert' in the print statements. solvw2's different output is achieved with different flow control logic
I've attached the tutorial and boxed the area. Hope it clears things up about what i'm asking
No telling why they wrote those print statements the way they did, but in the first two the integer variables had to be converted to a string because they are being concatenated (+) with a string http://dpaste.com/773542/ and the third is just printing the variable (which print knows how to do). The Idle shell is excellant for trying things out to see how they work. how many for loops does solve() have? how many for loops so solve1() and solve2() have?
Join our real-time social learning platform and learn together with your friends!