473,320 Members | 1,865 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Question about text in Python

Hi,

I've created a Python program that a user enteres one line of text which
will then create an acronym from that text.

What I want to add to the program is the abilty to rerun this process (where
the user enteres another line of text) until the user has had enough and
enters a blank line which would then end the program.

Can anyone help with this?

thanks

Apr 2 '07 #1
10 1421
Steve schrieb:
I've created a Python program that a user enteres one line of text which
will then create an acronym from that text.

What I want to add to the program is the abilty to rerun this process
(where the user enteres another line of text) until the user has had
enough and enters a blank line which would then end the program.
You can do this with a while loop. If the user enters a blank line you
can break out of the loop:
while true:
(some code)
if not line:
break

Thomas
Apr 2 '07 #2
On 4/2/07, Steve <st*******@removethisnowgmail.comwrote:
Hi,

I've created a Python program that a user enteres one line of text which
will then create an acronym from that text.

What I want to add to the program is the abilty to rerun this process (where
the user enteres another line of text) until the user has had enough and
enters a blank line which would then end the program.

Can anyone help with this?

thanks

--
http://mail.python.org/mailman/listinfo/python-list
Untested:

if __name__ == "__main__":
userinp=raw_input("Query>")
while userinp:
callmyabbrvfunction(userinp)
userinp=raw_input("Another Query>")
print "Exit: You have entered empty string !"

cheers,

--
----
Amit Khemka -- onyomo.com
Home Page: www.cse.iitd.ernet.in/~csd00377
Endless the world's turn, endless the sun's Spinning, Endless the quest;
I turn again, back to my own beginning, And here, find rest.
Apr 2 '07 #3
On Mon, 02 Apr 2007 18:48:00 +1000, Steve wrote:
Hi,

I've created a Python program that a user enteres one line of text which
will then create an acronym from that text.

What I want to add to the program is the abilty to rerun this process (where
the user enteres another line of text) until the user has had enough and
enters a blank line which would then end the program.

Can anyone help with this?
It isn't really a question about _text_. It's a question about programming
techniques.

Firstly, break the task into small pieces:

* get input (a line of text) from the user;
* make an acronym from the text;
* decide if you're done;
* if not, repeat from the beginning.

Now write code to do each piece.

Now all you need to do is create functions to do each sub-task:

def get_input():
"""Get input from the user."""
return raw_input("Please type a sentence. ")
def make_acronym(text):
"""Return an acronym from the given text."""
# you have already done this
.... do stuff ...
return acronym
def are_we_done():
"""Return a boolean flag indicating whether
we're done making acronyms.
"""
print "Would you like to make another acronym?"
print "Type Y or y for yes, N or n for no."
result = raw_input("Then press the Enter key. (y/n?) ")
return result in 'yY'
Now put them all together into a loop.
done = False # we're not done yet
while not done:
# repeat until we're done
text = get_input()
acronym = make_acronym(text)
print acronym
done = are_we_done()
There are lots of other ways of doing this. This one is (I think) the
easiest to understand, but there are other ways that are more
efficient but use more advanced concepts like exceptions. Have fun
exploring the different ways of doing this task.


--
Steven D'Aprano

Apr 2 '07 #4
Steve wrote:
What I want to add to the program is the abilty to rerun this
process (where the user enteres another line of text) until the
user has had enough and enters a blank line which would then end
the program.
Homework?

Regards,
Björn

--
BOFH excuse #106:

The electrician didn't know what the yellow cable was so he yanked
the ethernet out.

Apr 2 '07 #5
Yes it is.

Where else to ask for help but here.

Thanks for your help everyone.

I figured it out.

"Bjoern Schliessmann" <us**************************@spamgourmet.comwro te
in message news:57*************@mid.individual.net...
Steve wrote:
>What I want to add to the program is the abilty to rerun this
process (where the user enteres another line of text) until the
user has had enough and enters a blank line which would then end
the program.

Homework?

Regards,
Björn

--
BOFH excuse #106:

The electrician didn't know what the yellow cable was so he yanked
the ethernet out.
Apr 3 '07 #6
"Steve" <st*******@REMOVETHISNOWgmail.comwrites:
Yes it is [a homework question].

Where else to ask for help but here.
That's between you, your teacher, and your teaching institute's
plagiarism guidelines.

--
\ "I got a postcard from my best friend, it was a satellite |
`\ picture of the entire Earth. On the back he wrote, 'Wish you |
_o__) were here'." -- Steven Wright |
Ben Finney
Apr 3 '07 #7
On Tue, 03 Apr 2007 12:26:47 +1000, Ben Finney wrote:
"Steve" <st*******@REMOVETHISNOWgmail.comwrites:
>Yes it is [a homework question].

Where else to ask for help but here.

That's between you, your teacher, and your teaching institute's
plagiarism guidelines.

Plagiarism is a serious example of fraud, which is not only a crime but is
unethical as well. You don't need to be a student or an academic to commit
plagiarism. Anybody can commit plagiarism.

If we applied the plagiarism guidelines that university students labour
under to the rest of us, perhaps we'd be a little less quick to toss
accusations of plagiarism around so easily. If it is plagiarism for a
student to ask how to detect an empty line, then it is plagiarism for
any of us to ask how to do anything.

At the point that students are unable to ask for information because
they're accused of plagiarism, well, that's "a total collapse of critical
reasoning", to quote Professor Steven Dutch of the University of Wisconsin.

Citation: http://www.uwgb.edu/dutchs/PSEUDOSC/PlagShame.HTM
Accessed 2007-04-03.
If the Original Poster _accidentally_ sees a newsgroup post that answers
his question -- "Oh, so that's how you exit a loop in Python!" -- is that
plagiarism? Or is it only plagiarism if he _asks_ for the information
first? Does he have to spend the rest of his life as a Python coder giving
credit to J. Random Hacker for using "his" technique of "using break to
exit a while loop"?

None of this is to excuse students who try to have their homework done for
them, or well-meaning but foolish people who, in response to a simple
question end up providing an entire working piece of code, essentially
doing the student's homework for them. Plagiarism does exist, and it is
fraud. But I'm sickened and saddened to see how plagiarism has been
bastardised by academia, turning it from serious fraud to trivial re-use
of phrases and ideas, and even _learning things from anyone someone other
than your lecturer_.

That's what it has come to. If you ask "how do I detect the user has
entered an empty line in raw_input?", you're deemed to be committing
fraud. WTF? There's a gulf the size of the Atlantic Ocean between
_learning_ and _committing fraud_, and we're so frightened by the thought
that somebody might fraudulently claim another person's ideas (which begs
the question of whether people can own ideas) that we're prohibiting
learning except through a couple of narrowly approved channels.

If you think I'm exaggerating, I challenge you to read Professor Dutch's
pages on plagiarism:

http://www.uwgb.edu/dutchs/PSEUDOSC/PlagShame.HTM
http://www.uwgb.edu/dutchs/PSEUDOSC/PlagiarNonsense.HTM

I challenge you to try to work as a coder, whether professional or
amateur, under the same restrictions that we've been placing on students.
I can't count the number of times people write to comp.lang.python asking
"How do I transmogrify the frombulator?" And let's not even mention
copying code snippets posted on Usenet.

These things are not fraud. They are learning.

This is not a call to turn a blind eye for plagiarism, or to do students
homework for them. It's a plea for common-sense. We're not bound by
university guidelines, or universities' over-broad definition of
plagiarism, and we don't have to live by them. We are ethically bound not
to do student's homework for them -- but that doesn't mean we're bound to
refuse to answer their reasonable questions, or to treat those who are
looking for help as frauds _just because they are a student_.

--
Steven D'Aprano

Apr 3 '07 #8
Steven D'Aprano <st***@REMOVEME.cybersource.com.auwrites:
On Tue, 03 Apr 2007 12:26:47 +1000, Ben Finney wrote:
"Steve" <st*******@REMOVETHISNOWgmail.comwrites:
Yes it is [a homework question].

Where else to ask for help but here.
That's between you, your teacher, and your teaching institute's
plagiarism guidelines.

Plagiarism is a serious example of fraud, which is not only a crime
but is unethical as well. You don't need to be a student or an
academic to commit plagiarism. Anybody can commit plagiarism.

If we applied the plagiarism guidelines that university students
labour under to the rest of us, perhaps we'd be a little less quick
to toss accusations of plagiarism around so easily.
I agree with the severity of such an accusation, which is why I didn't
make it in this case.

--
\ "[T]he question of whether machines can think [...] is about as |
`\ relevant as the question of whether submarines can swim." -- |
_o__) Edsger W. Dijkstra |
Ben Finney
Apr 3 '07 #9
Steve wrote:
Yes it is.

Where else to ask for help but here.
http://www.catb.org/~esr/faqs/smart-....html#homework

Regards&Good luck,
Björn

--
BOFH excuse #247:

Due to Federal Budget problems we have been forced to cut back on
the number of users able to access the system at one time. (namely
none allowed....)

Apr 3 '07 #10
"Steven D'Aprano" <ste..e@REMOVEME.c....rce.com.auwrote:

8< --------
This is not a call to turn a blind eye for plagiarism, or to do students
homework for them. It's a plea for common-sense. We're not bound by
university guidelines, or universities' over-broad definition of
plagiarism, and we don't have to live by them. We are ethically bound not
to do student's homework for them -- but that doesn't mean we're bound to
refuse to answer their reasonable questions, or to treat those who are
looking for help as frauds _just because they are a student_.
I agree - It is not fraud if the OP says he is a student, and asks for help
on something that puzzles him.

It would be fraud if he gets a "full answer" here, and represents it as
"his own work".

It would also be stupid, as its a sure fire way of failing your
examinations.

Getting clarification on some point here is no different from looking it
up in a library, except that its more risky - some wag may lie to the
poor bugger...

- Hendrik
Apr 4 '07 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Gerard Flanagan | last post by:
Hello I have the following code: #### builder.py ######### class HtmlBuilder(object): @staticmethod def page(title=''): return HtmlPage(title)
6
by: kath | last post by:
Hi all, Platform: winxp Version: Python 2.3 I have a task of reading files in a folder and creating an one excel file with sheets, one sheet per file, with sheet named...
0
by: Eric_Dexter | last post by:
I know this might be the wrong place to ask but I recently modified the ogl example from wxpython and it works fine in spe but when I call it from other programs it wierds out because of the run.py...
11
by: proctor | last post by:
hello, i have a regex: rx_test = re.compile('/x()*x/') which is part of this test program: ============ import re
0
by: bruce | last post by:
hey guys... i managed to solve what i was attempting.. my goal was rather simple, to be able to have a python script, call a ruby app, and be able to return a value from the ruby (child) app to...
8
by: joemacbusiness | last post by:
Hi All, How do I format printed data in python? I could not find this in the Python Reference Manual: http://docs.python.org/ref/print.html Nor could I find it in Matloff's great tutorial:...
0
by: John Krukoff | last post by:
On Wed, 2008-09-03 at 13:36 -0700, bruce wrote: Well, you could just do the test (and the count!) in the xpath expression: count( //tr/td ) It sounds like you're not familiar with xpath? I...
4
by: John Townsend | last post by:
Joe had a good point! Let me describe what problem I'm trying to solve and the list can recommend some suggestions. I have two text files. Each file contains data like this: Test file 1234 4567...
13
by: Liang Chen | last post by:
Hope you all had a nice weekend. I have a question that I hope someone can help me out. I want to run a Python program that uses Tkinter for the user interface (GUI). The program allows me to type...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.