13.2. Interactive Stories with Input

You can use if statements to make a story interactive where the reader picks from several possible next actions. The input method will display the string and return what the user types. You can check if two strings have the same characters using == in Python.

Before you keep reading...

Making great stuff takes time and $$. If you appreciate the book you are reading now and want to keep quality materials free for other students please consider a donation to Runestone Academy. We ask that you consider a $10 donation, but if you can give more thats great, if $10 is too much for your budget we would be happy with whatever you can afford as a show of support.

What should the program do if the user enters something besides in, left, or right? Fix the code above to let the user know what went wrong. Also add another possibility like “out”.

Note

Discuss topics in this section with classmates.

Show Comments
You have attempted 1 of 4 activities on this page