My First Python Script!

by Marina Martin

in Personal

My MacBook hard drive appears to have bit the dust, and Damon has graciously allowed me to use his old Powerbook until the snow goes away and I can safely trek to the Apple Store for a replacement.

Clearly his Powerbook is infused with Python voodoo, because I had every intention of working on my PHP skillz over the holidays, yet I somehow found my way to the MIT OpenCourseware’s “Intro to Computer Science” course and its corresponding Python tutorials.

So, here is my first working script – The Socratic Methodizer!

print “Welcome to The Socratic Methodizer!\nThink you know the truth? Let’s test that premise!”
premise = raw_input(“Enter your premise: “)
result = raw_input(“Is there ever a time when this is NOT true? “)
result = ”.join (result.split()).lower()
while result == “yes”:
print “Then you better fix it!”
premise = raw_input(“Enter your new premise, taking the exception into account: “)
result = raw_input(“Is there ever a time when this is NOT true? “)
result = ”.join (result.split()).lower()
if result == “no”:
print “You have found truth!”
else:
print “Huh? I don’t speak your language.”

Sample output:

MyMac-4:~/Desktop apple$ python socrates.py
Welcome to The Socratic Methodizer!
Think you know the truth? Let’s test that premise!
Enter your premise: Apples are red.
Is there ever a time when this is NOT true? Yes
Then you better fix it!
Enter your new premise, taking the exception into account: Apples are red and green.
Is there ever a time when this is NOT true? Yes
Then you better fix it!
Enter your new premise, taking the exception into account: Apples are red, green, and yellow.
Is there ever a time when this is NOT true? Yes
Then you better fix it!
Enter your new premise, taking the exception into account: Apples come in many different colors.
Is there ever a time when this is NOT true? No
You have found truth!

Now all I need to do is … figure out how to error-check (my else is a lame cop-out) and then figure out how to make it work outside of the command line (ha!).

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • email
  • Identi.ca
  • LinkedIn
  • Netvibes
  • Reddit
  • StumbleUpon
  • Technorati

{ 2 comments… read them below or add one }

1 Calvin Freitas December 27, 2008 at 12:31 pm

Sounds like a perfect recipe for a single-serving site (http://kottke.org/08/02/single-serving-sites).

2 An Bui April 28, 2009 at 5:51 pm

i SO could have used this in law school!

Leave a Comment

Previous post:

Next post:

One of Marina Martin’s Blogs