LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 03-28-2005, 01:52 PM   #1
dezza
Member
 
Registered: Nov 2004
Location: Denmark
Distribution: ArchLinux, Debian
Posts: 129

Rep: Reputation: 18
7.3 "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:

Code:
prefixes = "JKLMNOPQ"
suffix = "ack"

for letter in prefixes:
  print letter + suffix
like ..

Code:
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..
 
Old 03-28-2005, 03:31 PM   #2
APB_4
Member
 
Registered: Nov 2004
Location: England
Distribution: Ubuntu 9.04; Crunchee; EEE Xandros
Posts: 289

Rep: Reputation: 30
How about
Code:
prefixes = "JKLMNOPQ"
suffix = "ack"

for letter in prefixes:
  if letter=="O":letter=letter+"u"
  elif letter=="Q":letter=letter+"u"
  print letter + suffix
 
Old 03-29-2005, 09:30 AM   #3
dezza
Member
 
Registered: Nov 2004
Location: Denmark
Distribution: ArchLinux, Debian
Posts: 129

Original Poster
Rep: Reputation: 18
Juack
Kuack
Luack
Muack
Nuack
Ouack
Puack
Quack

Is the output of your code.
 
Old 03-29-2005, 09:32 AM   #4
APB_4
Member
 
Registered: Nov 2004
Location: England
Distribution: Ubuntu 9.04; Crunchee; EEE Xandros
Posts: 289

Rep: Reputation: 30
It worked when I did it. Post your code
 
Old 07-09-2008, 04:15 PM   #5
TzaB
LQ Newbie
 
Registered: Jul 2008
Distribution: Debian GNU/Linux
Posts: 8

Rep: Reputation: 0
First post on your lovely forum, and posting on a bit old post (from 2005). But i want to answer to the problem, because i had the same when this afternoon i tried to do this exercise from the book "How to Think Like a Computer Scientist"

So this is my answer

Code:
prefixes = "JKLMNOPQ"
suffix = "ack"

for x in prefixes:
    if x=="O" or x=="Q":
        print x+"u"+suffix
    else:
        print x+suffix
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Telling people to use "Google," to "RTFM," or "Use the search feature" Ausar General 77 03-21-2010 11:26 AM
"Xlib: extension "XFree86-DRI" missing on display ":0.0"." zaps Linux - Games 9 05-14-2007 03:07 PM
User "list" running process "python" TroelsSmit Linux - Newbie 2 02-22-2005 04:55 AM
Lost DHCP Lease when putting computer in "Standby" mode for a "long" time pnellesen Linux - Networking 1 01-06-2005 11:44 PM
Python compilation error, "module search path"etc.. mindfestival Linux - Newbie 0 05-31-2004 02:52 AM


All times are GMT -5. The time now is 07:28 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration