Variables.

A

administrata

I wrote this, It's a bit lame though

I = "Allen"
me = "Allen"
my = "Allen's"

print \
"""
%s woke up early in the morning. But, it was unusal by %s. %s pillow
was with %s. %s didn't want to wake up But, %s tried my best and woke up.
it was so amazing!""" % (I,me,my,me,I,I)

raw_input("\n\\t\t\t- The End -")

But it looks like this...

Allen woke up early in the morning. But, it was unusal by Allen.
Allen's pillow
was with Allen. Allen didn't want to wake up But, Allen tried my best and woke up.
it was so amazing

- The End -

HELP plz
 
C

Christos TZOTZIOY Georgiou

I wrote this, It's a bit lame though

I = "Allen"
me = "Allen"
my = "Allen's"

print \
"""
%s woke up early in the morning. But, it was unusal by %s. %s pillow
was with %s. %s didn't want to wake up But, %s tried my best and woke up.
it was so amazing!""" % (I,me,my,me,I,I)

raw_input("\n\\t\t\t- The End -")

But it looks like this...

Allen woke up early in the morning. But, it was unusal by Allen.
Allen's pillow
was with Allen. Allen didn't want to wake up But, Allen tried my best and woke up.
it was so amazing

- The End -

It looks exactly how it should, based on what you gave it.

Try the following changes:
I = "Allen"
me = "Allen"
my = "Allen's"

to

xyzzy = "I"
footy = "me"
spike = "my"

and then change the last line of the triple-quoted string:
it was so amazing!""" % (I,me,my,me,I,I)

to

it was so amazing!""" % (xyzzy,footy,spike,footy,xyzzy,xyzzy)

Let us know what you expect to print after these changes.

By all means --what's the problem exactly?
 
S

Simon Brunning

I wrote this, It's a bit lame though

I = "Allen"
me = "Allen"
my = "Allen's"

print \
"""
%s woke up early in the morning. But, it was unusal by %s. %s pillow
was with %s. %s didn't want to wake up But, %s tried my best and woke up.
it was so amazing!""" % (I,me,my,me,I,I)

One thing that you might want to do is to use a dictionary to provide
the values, like so:

my_values = {"I": "Simon", "me": "Simon", "my": "Simon's"}

print """%(I)s woke up early in the morning. But, it was unusal by
%(me)s. %(my)s pillow
was with %(me)s. %(I)s didn't want to wake up But, %(I)s tried my best
and woke up.
It was so amazing!""" % my_values
raw_input("\n\\t\t\t- The End -")

But it looks like this...

Allen woke up early in the morning. But, it was unusal by Allen.
Allen's pillow
was with Allen. Allen didn't want to wake up But, Allen tried my best and woke up.
it was so amazing

- The End -

What did you *expect* it to do?
 
B

bruno modulix

administrata said:
I wrote this, It's a bit lame though
(snip code - see other answers in this thread)
raw_input("\n\\t\t\t- The End -")

Why on earth are you using raw_input() here ?

No one can help you if you don't explain your problem. We are not
psychic enough to read your mind !-)

(and please : avoid SCREAMING and l33t speak too...)
 
J

Jeff Shannon

bruno said:
(snip code - see other answers in this thread)



Why on earth are you using raw_input() here ?

This is a fairly common idiom, on Windows at least. If running a
console app from Explorer, the console will close as soon as the app
terminates. Using raw_input() at the end of the app means that it
won't close until the user hits Enter.
No one can help you if you don't explain your problem. We are not
psychic enough to read your mind !-)

Indeed -- it looks like this worked perfectly to me, so the issue is
in what's expected. :)

Jeff Shannon
Technician/Programmer
Credit International
 
B

Bruno Desthuilliers

Jeff Shannon a écrit :
This is a fairly common idiom, on Windows at least.

Windows only, I guess...
If running a
console app from Explorer, the console will close as soon as the app
terminates. Using raw_input() at the end of the app means that it won't
close until the user hits Enter.

So why dont you just open the console before running the app, then ?-)

Bruno
 
J

Jeff Shannon

Bruno said:
Jeff Shannon a écrit :


So why dont you just open the console before running the app, then ?-)

Well, *I* generally do. ;) But for those with relatively little
computing experience that *hasn't* been through the Windows GUI, the
thought of opening a console isn't necessarily an obvious one.
(Modern versions of Windows seem to try to hide the console as much as
they can....)

Jeff Shannon
Technician/Programmer
Credit International
 
A

administrata

sry, I mean the problem is... about lining

it doesn't look like this...

Allen woke up early in the morning. But, it was unusal by Allen.
Allen's pillow was with Allen. Allen didn't want to wake up But, Allen
tried my best and woke up. it was so amazing
 
R

Robert Kern

administrata said:
sry, I mean the problem is... about lining

it doesn't look like this...

Allen woke up early in the morning. But, it was unusal by Allen.
Allen's pillow was with Allen. Allen didn't want to wake up But, Allen
tried my best and woke up. it was so amazing

In the future, please follow the advice given on this page:

http://www.catb.org/~esr/faqs/smart-questions.html

Also, consider joining the tutor mailing list.

http://mail.python.org/mailman/listinfo/tutor

For this problem, see the textwrap module in the standard library.

http://docs.python.org/lib/module-textwrap.html

--
Robert Kern
(e-mail address removed)

"In the fields of hell where the grass grows high
Are the graves of dreams allowed to die."
-- Richard Harter
 
T

Terry Hancock

sry, I mean the problem is... about lining

it doesn't look like this...

Allen woke up early in the morning. But, it was unusal by Allen.
Allen's pillow was with Allen. Allen didn't want to wake up But, Allen
tried my best and woke up. it was so amazing

In a triple-quoted string, newlines are significant.

Compare:
.... first line of text
.... second line of text
.... third line of text
.... """.... "second line of text "
.... "third line of text")
first line of text
second line of text
third line of text

Note that strings that appear together without punctuation are concatenated
*before* byte-compiling, whereas using "+" creates code to concatenated the
strings. This will rarely matter, but it means that the idiom above is completely
equivalent to a long string on a single line, which is probably what you wanted.

You need the parentheses to tell Python that the expression is not complete,
so it won't throw a syntax error when you go to the next line.

There are also more sophisticated ways of processing text, of course -- study the
"textwrap" module, for example.

Cheers,
Terry
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,219
Messages
2,571,127
Members
47,744
Latest member
FrederickM

Latest Threads

Top