Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Mar 28th, 2005, 12:58 PM   #1
dezza
Newbie
 
dezza's Avatar
 
Join Date: Mar 2005
Location: Denmark
Posts: 16
Rep Power: 0 dezza is on a distinguished road
Send a message via ICQ to dezza Send a message via MSN to dezza
Thumbs up "How to think like a computer scientist - Python"

Hello everyone I am glad that I found this forum by searching trough Google, hope you can help me out in my attempt to fully understand Python.

I have followed the guide "How To Think Like a Computerscientist - Python" and i've come to this place where I can't think of any creative ways to do what the exercise says:

As an exercise, modify the program to fix this error.

(It's the Jack, Kack, Lack, Mack, Nack, Ouack, Pack, and Quack Duckling exercise thing I am working on)

http://www.ibiblio.org/obp/thinkCSpy/chap07.htm#3

I know that I could simply just make several of the example code in alphabetical order:

prefixes = "JKLMNOPQ"
suffix = "ack"

for letter in prefixes:
  print letter + suffix

like ..

prefix1 = "JKLMN"
prefix2 = "O"
prefix3 = "P"
prefix4 = "Q"
suffix1 = "ack"
suffix2 = "uack"

for letter in prefix1:
  print letter + suffix1

for letter in prefix2:
  print letter + suffix2

for letter in prefix3:
  print letter + suffix1

for letter in prefix4:
  print letter + suffix2

But I am not sure if that is what is meant to be done in this guide? Maybe someone who have done this guide can answer this?

Once again, I hope this forum will grow big and become the main spot for programming help..
dezza is offline   Reply With Quote
Old Mar 28th, 2005, 2:02 PM   #2
peace_of_mind
Professional Programmer
 
peace_of_mind's Avatar
 
Join Date: Sep 2004
Location: Hell if I know most of the time
Posts: 435
Rep Power: 4 peace_of_mind is on a distinguished road
Send a message via MSN to peace_of_mind Send a message via Yahoo to peace_of_mind
You seem to have done exactly what is being asked of you in this exercise. Congrats and keep up the good work.
__________________
Amateurs built the ark
Professionals built the Titanic

peace_of_mind is offline   Reply With Quote
Old Mar 28th, 2005, 2:47 PM   #3
Moldz
Programmer
 
Moldz's Avatar
 
Join Date: Feb 2005
Posts: 54
Rep Power: 4 Moldz is on a distinguished road
I'm not sure if they covered lists at that point, but you could also do:
prefix = ['J', 'K', 'L', 'M', 'N', 'Ou', 'P', 'Qu']
suffix = 'ack'
for letter in prefix:
    print letter + suffix
Your solution works, but it's not the easiest code to maintain. Try adding a few prefixes to both codes and see which is easier to modify, ie - make it also say Tack, Uack, Vack. Which is easier?
Moldz is offline   Reply With Quote
Old Mar 29th, 2005, 1:51 AM   #4
Berto
Programming Guru
 
Join Date: Aug 2004
Posts: 1,022
Rep Power: 5 Berto is on a distinguished road
Send a message via AIM to Berto Send a message via MSN to Berto
i would like to say to the poster cheers for the link i have been hunting down a fun python tutorial
Berto is offline   Reply With Quote
Old Mar 29th, 2005, 9:41 AM   #5
dezza
Newbie
 
dezza's Avatar
 
Join Date: Mar 2005
Location: Denmark
Posts: 16
Rep Power: 0 dezza is on a distinguished road
Send a message via ICQ to dezza Send a message via MSN to dezza
Wow, I just got my own thoughts confirmed.. What a really nice place this is, with nice people and positive helping posts, thank you for your introduction

#4 (Berto)
Yeah it's really nice, you should check out the other books at http://ibiblio.org/obp especially the Python ones.. Makes programming a little funnier.

I can also recommend these books from a friend who is using them in a programming course he's running at the university he is employed.
http://www.oreilly.com/catalog/python2/index.html
http://www.oreilly.com/catalog/lpython2/index.html

Gotta love Python ..
http://home.no/dezza/python
Prolly the youngest python programmer in the world ..
I know this is found on O'Reilly somewhere but I couldn't find the destination and I was to lazy to look for it, just kept it for saving.

#2 (peace_of_mind)
Thank you, and what a nice signature of yours, makes a new programmer welcome into the scene.

#3 (Moldz)
Thanks, worked out really fine! I think it have been mentioned, i've read the book (not fully though) before and I know that there is such a thing as lists Like you can do things like this:

print prefix[0]+" what a nice functiona!"

By the way, how do I get "return" to print when running the code as script? I know that you can see the + and - in the interpreter, but can you make it print the true/false statement?

I need it in this case:
import string
def isLower2(ch):
  return ch in string.lowercase
__________________
Come in and have a talk!
#programmingforums @ Freenode

Specialities: Linux, XHTML/HTML and CSS.
Learning: Python

Folding@Home Stats

System Requirements: Windows 9x/ME/2000/XP or better
Okay, that makes it run on Linux right?

Last edited by dezza; Mar 29th, 2005 at 2:18 PM.
dezza is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 8:21 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC