Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDinko Galetic <dgaletic@everflame.(none)>2010-06-24 19:36:43 (GMT)
committer Dinko Galetic <dgaletic@everflame.(none)>2010-06-24 19:36:43 (GMT)
commite84f76c6e94b0149183872276d10eeb37252dc7c (patch)
tree64827e895287057df5e048b0a85928f978ea94f6
parent37fdb92019e01a27856b5e528aff7bb45228db49 (diff)
Added the introduction for the tutorial.
-rw-r--r--library/introduction.py104
1 files changed, 104 insertions, 0 deletions
diff --git a/library/introduction.py b/library/introduction.py
new file mode 100644
index 0000000..21134ba
--- /dev/null
+++ b/library/introduction.py
@@ -0,0 +1,104 @@
+def run():
+ print """Hello there, and welcome to PyTutor.
+Before we continue, please tell me your name. You can type it in right here:"""
+ answer = "no"
+ while answer == "no" or answer == "No":
+ name = raw_input(">>> ")
+ print "Your name is " + name + ". Did I get it right? You can answer \"yes\" or \"no\"."
+ answer = raw_input(">>> ")
+ # Support other answers?
+ while answer != "yes" and answer != "no" and answer != "Yes" and answer != "No":
+ print "Please answer \"yes\" or \"no\"."
+ answer = raw_input(">>> ")
+ if answer == "no" or answer == "No":
+ print "Please enter your name again: "
+
+ print "Hello again, " + name + """. Before you is a set of lessons about computer programming, or just "programming" for short. I will present them to you and guide you through them. You can also read them yourself without my guidance (*somehow*).
+If at any time you wish to quit, just type in \"quit\". You can always resume the tutorial later by simply restarting it and introducing yourself again.
+To continue, just press enter."""
+ if raw_input(">>> ") == "quit":
+ quit()
+ print """So, the beginning. What is computer programming? In most cases, it is writing your computer what you want it to do, and that is what we will be doing.
+Fox example, you could tell your computer to make some calculations for you. Whenever you see ">>> " on the screen, that means that you can type. *(explain this differently)*
+Try typing "print 10 + 3". """
+ exactly = True
+ while True:
+ user_input = raw_input(">>> ")
+ if user_input == "quit":
+ quit()
+ elif user_input == "skip":
+ print "Skipping this example, moving on..."
+ break
+ elif user_input == "print 10 + 3":
+ print "13"
+ break
+ elif user_input[0:6] == "print ":
+ exactly = False
+ try:
+ print eval(user_input[6:])
+ # This or the alternative?
+ # exec(user_input)
+ break
+ except:
+ print "That won't work. Try what I suggested."
+ else:
+ print "You don't have to type exactly the numbers I asked you to, but you should start with \"print \"."
+ print
+ print "Press enter to continue."
+ user_input = raw_input(">>> ")
+ print "Good.",
+ if exactly == False:
+ print "That wasn't exactly what I asked you to type, but it works as well.",
+ print """Please - try some more! You can use any numbers and other mathematical operations (+, -, *, /, **, % ) as well. A few examples: "print 5 * 5", "print 30 / 3", "print 1 + 2 + 3 + 4 - 5". When you are done trying your calculations, simply type "done" and I will continue."""
+ user_input = raw_input(">>> ")
+ while user_input != "done":
+ if user_input == "quit":
+ quit()
+ elif user_input == "skip":
+ print "Skipping this example, moving on..."
+ break
+ elif user_input[0:6] == "print ":
+ try:
+ print eval(user_input[6:])
+ except:
+ print "That won't work. Try something else."
+ else:
+ print "You should start with \"print \" for now. We'll practice other things later."
+ user_input = raw_input(">>> ")
+ print
+ print """Congratulations! If you have never done something like this before, you've just programmed for the first time and written your first short computer program."""
+ print """\nThere are many examples of programs available in Pippy. If you haven't already tried to run them, you can do that now - type "quit" and you can resume the tutorial later. Bear in mind that most of those programs consist of over a hundred lines of code (what we've tried so far had only one line) and that it will all look very confusing to you - but that is OK. As we advance through our lessons, you will be able to understand more and more of those examples, and not only that - you will be able to write your own! For now, just look at them to see out what programs look like and run them to see what each of them does. """
+ print "Press enter to continue."
+ user_input = raw_input(">>> ")
+ print """There is one more thing I would like you to think about before we move to the the next chapter. What do you think would happen if we ran this code?
+
+a = 5
+b = 15
+print b / a
+
+Think about it, then run it to see if you got it right, and I'll be waiting with the next chapter!
+Type "done" when you are finished."""
+
+ # TODO: This could could/should go into a function.
+ user_input = raw_input(">>> ")
+ while user_input != "done":
+ if user_input == "quit":
+ quit()
+ elif user_input == "skip":
+ print "Skipping this example, moving on..."
+ break
+ elif user_input[0:6] == "print ":
+ try:
+ # TODO: think about replacing eval() with exec.
+ # eval() is safer, but can't go without exec here.
+ print eval(user_input[6:])
+ except:
+ print "That won't work. Try something else."
+ else:
+ try:
+ exec user_input
+ except:
+ print "Hm, that won't work. Try typing what I suggested."
+ user_input = raw_input(">>> ")
+
+ print "Goodbye, " + name + "!"