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\
pretty simple exercise, mostly just had to correct spelling mistakes.
Agreed. A simple exercise. I was surprised with the flexibility when it came to double-quotes or single quotes.
On Python IDLE, click file, then new window. You can easily type your code and then run it.
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
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.
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'.
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.
>>>
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
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.
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.