This is the P2PU Archive. If you want the current site, go to www.p2pu.org!

Learn Python the Hard Way

My recent threads

You haven't posted any discussions yet.

Recently updated threads

Exercise 1

Go back to: General discussion

Here is the forum for Exercise 1.

My code for this exercise looks like this.  I've spaced it so it is easier to read.
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

1 # this line will print the words Hello World using the print command.

2 print "Hello World!"

3 # this line prints the words Hello Again using the print command.
4 print "Hello Again"

5 # same idea, different text
6 print "I like typing this."

7 # same idea, different text
8 print "this is fun."

9 # same idea, different text
10 print 'Yay! Printing.'

11 # this line prints the text I'd much rather you 'not' and notice the ' around not
12 print "I'd much rather you 'not'."

13 # this line prints the text I said do not touch this and notice the " around the word said
14 print 'I "said" do not touch this.'

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Output from this code produces the following.
C:\Python27\ python ex1.py
Hello World!
Hello Again
I like typing this.
This is fun.
Yay! Printing.
I'd much rather you 'not'.
I "said" do not touch this.
C:\Python27\
pborzel's picture
pborzel
Thu, 2011-01-20 21:44

pretty simple exercise, mostly just had to correct spelling mistakes.

Steve Phelps's picture
Steve Phelps
Thu, 2011-01-20 21:54

Agreed. A simple exercise. I was surprised with the flexibility when it came to double-quotes or single quotes.

Amene Katanda's picture
Amene Katanda
Fri, 2011-01-21 11:06

On Python IDLE, click file, then new window. You can easily type your code and then run it.

andy gomer's picture
andy gomer
Sat, 2011-01-22 20:57

Hello Everybody. This is my Example 1. I also did the extra credit, so your output might not look exactly like mine.

Hello World!
Hello Again
I like typing this
This is fun.
Yay! Printing.
I'd much rather you 'not'.
I "said" do not touch this.
I printed another line

Trent Branson's picture
Trent Branson
Sun, 2011-01-23 10:32

Hey Everyone. Here's my input and output:
I did extra credit as well
-- Input --
# Aim: To learn to use the print statement printing some lines.
# You can put double (") or single(') quotes
print "Hello World!"
print "Hello Again"
print "I like typing this."
print "This is fun."
print 'Yay! Printing.'
# if you use " then the ' won't effect the statement
print "I'd much rather you 'not'."
# it works the other way around as well
print 'I "said" do not touch this.'
print "Another line."
# a hash tag inserts a 1 line comment. So none of the line executes.

-- Output --

Hello World!
Hello Again
I like typing this.
This is fun.
Yay! Printing.
I'd much rather you 'not'.
I "said" do not touch this.
Another line.

Naku Mayo's picture
Naku Mayo
Wed, 2011-01-26 03:09

Here is my ex1.py script

print "Hello World!"
print "Hello Again"
print "I like typing this."
print "This is fun."
print 'Yay! Printing.'
print "I'd much rather you 'not'."
print 'I "said" do not touch this.'

Output:

$ python ex1.py
Hello World!
Hello Again
I like typing this.
This is fun.
Yay! Printing.
I'd much rather you 'not'.
I "said" do not touch this.

Extra Credit:
#print "Hello World!"
#print "Hello Again"
#print "I like typing this."
#print "This is fun."
#print 'Yay! Printing.'
print "I'd much rather you 'not'."
#print 'I "said" do not touch this.'
print "One more line for extra credit."

output:
$ python ex1.py
I'd much rather you 'not'.
One more line for extra credit.

#print "Hello World!"
#print "Hello Again"
#print "I like typing this."
#print "This is fun."
#print 'Yay! Printing.'
print "I'd much rather you 'not'."
#print 'I "said" do not touch this.'
#print "One more line for extra credit."

Output:
$ python ex1.py
I'd much rather you 'not'.

Red Olaf's picture
Red Olaf
Wed, 2011-01-26 22:14

Just the output for exercise 1 and extra credit.

Python 2.7.1 (r271:86882M, Nov 30 2010, 09:39:13)
[GCC 4.0.1 (Apple Inc. build 5494)] on darwin
Type "copyright", "credits" or "license()" for more information.
>>> ================================ RESTART ================================
>>>
Hello World!
Hello Again
I like typing this.
This is fun
Yay! Printing.
I'd much rather you 'not'.
I "said" do not touch this.
>>> ================================ RESTART ================================
>>>
Hello World!
Hello Again
I like typing this.
This is fun.
Yay! Printing.
I'd much rather you 'not'.
I "said" do not touch this.
This is another line for extra credit.
>>> ================================ RESTART ================================
>>>
Hello World!
>>> ================================ RESTART ================================
>>>

An 'octothorpe' is used for commenting in Python scripts.
>>>

jodischneider's picture
jodischneider
Sun, 2011-01-30 22:35

print "Hello World!"
print "Hello Again"
print "I like typing this."
print "This is fun."
print 'Yay! Printing.'
print "I'd much rather you 'not'."
print 'I "said" do not touch this.'

==============

me$ python ex1.py
Hello World!
Hello Again
I like typing this.
This is fun.
Yay! Printing.
I'd much rather you 'not'.
I "said" do not touch this.
me $

=======
Did EC 1-3

Tyler Brown's picture
Tyler Brown
Mon, 2011-01-31 04:15

Just the output (Pre EC)
Hello World!
Hello Again!
I like typing this.
This is fun.
Yay! Printing.
I'd much rather you 'not'.
I "said" do not touch this.

Dorene DeMars's picture
Dorene DeMars
Thu, 2011-02-03 08:25

Made an initial mistake on Line 5 using a double quote mark at the beginning of the line and a single at the end. It was an easy fix and the script ran correctly after that.