Hardware Reference
In-Depth Information
!= means not equal, so the while loop repeats whilst the variable userAnswer is not
equal  to no . After printing an insult the code gets input from the user and updates the
userAnswer variable ready for the test before the start of the next loop.
raw_input was renamed input in Python 3.
Consider what the loop would look like if you didn't create a function - you'd have to include
all the code inside the loop body. his makes the code harder to read, and means you'd have
to retype it in each of these examples!
If your program gets stuck in an ininite loop , a loop that never ends, you can stop your program
by pressing Ctrl + C.
Putting It All Together
You should now have a program that generates a torrent of insults! his chapter has covered
the basics of programming in Python. Look at each line in the examples and see if you under-
stand what each part does. hen, to personalise your program, you could make it produce
diferent insults depending on the user's name. For example, you could make it say some-
thing nice only if your name is entered, or you could change the number of insults it gener-
ates depending on the user or their age (such as a younger brother). You could print “really
old” for people over a certain age, or if you're clever¸ you could use a loop to print an addi-
tional “really ” for every decade someone has been alive.
he main thing is to not be afraid of changing things to see what happens. Just as you can't
learn to paint without practising, you won't learn how to program without experimenting.
hroughout this topic, there are ideas to change the projects to make them your own and to
make the computer do what you want it to do.
 
Search WWH ::




Custom Search