Difference between revisions of "CSC111 Homework 1 2015"

From dftwiki3
Jump to: navigation, search
(Problem #3)
(Problem #5)
Line 146: Line 146:
 
=Problem #5=
 
=Problem #5=
 
<br />
 
<br />
Edit the program of the HW1 P5 section on Moodle, so that its output becomes the one shown below:
+
Copy the incomplete program below into IDLE, and edit it until its output is '''exactly''' the same as the one shown in the right column of the table below.  Be careful, as the Moodle testing program counts extra spaces or extra blank lines in your output as incorrect!
 +
 
 +
Make sure you click on '''evaluate''' in Moodle to make sure your program receives a grade.
 
<br />
 
<br />
 
{| class="wikitable" width="100%"
 
{| class="wikitable" width="100%"
Line 181: Line 183:
 
|}
 
|}
 
<br />
 
<br />
 +
<!-- ---------------------------------------------------------------------------------------------------- -->
 +
=Problem 6=
 +
<br />
 +
Copy the incomplete program below into IDLE, and edit it until its output is '''exactly''' the same as the one shown in the right column of the table below.  Be careful, as the Moodle testing program counts extra spaces or extra blank lines in your output as incorrect!
 +
 +
Make sure you click on '''evaluate''' in Moodle to make sure your program receives a grade.
 +
 +
<br />
 +
{| class="wikitable" width="100%"
 +
! incomplete program
 +
! output
 +
|-
 +
|
 +
<source lang="python">
 +
# Homework 1, Problem
 +
# Homework 1, Problem 6
 +
 +
def greetLength( person ):
 +
    bar = "---------------------"
 +
    print( bar )
 +
    print( "Hello", person )
 +
 +
greetLength( "John" )
 +
greetLength( "Emily" )
 +
greetLength( "Jo" )
 +
</source>
 +
|
 +
<source lang="text">
 +
---------------------
 +
Hello John how are you?
 +
---------------------
 +
Hello Emily how are you?
 +
---------------------
 +
Hello Jo how are you?
 +
</source>
 +
|}
 +
<br />
 +
<br />
 +
<!-- ---------------------------------------------------------------------------------------------------- -->
 +
=Problem 7=
 +
<br />
 +
Copy the incomplete program below into IDLE, and edit it until its output is '''exactly''' the same as the one shown in the right column of the table below.  Be careful, as the Moodle testing program counts extra spaces or extra blank lines in your output as incorrect!
 +
 +
Make sure you click on '''evaluate''' in Moodle to make sure your program receives a grade.
 +
 +
<br />
 +
{| class="wikitable" width="100%"
 +
! incomplete program
 +
! output
 +
|-
 +
|
 +
<source lang="python">
 +
# Homework 1, Problem 7
 +
 +
person1 = "Maria Callas"
 +
person2 = "Sir Elton John"
 +
person3 = "Lady Gaga"
 +
 +
def greetLength( person ):
 +
    bar = "---------------------"
 +
    print( bar )
 +
    noChars = len( person )
 +
    print( person, "<==" )
 +
    print(  noChars, "characters" )
 +
 +
greetLength( person2 )
 +
greetLength( person2 )
 +
greetLength( person2 )
 +
</source>
 +
|
 +
<source lang="text">
 +
---------------------
 +
==> Maria Callas <==
 +
Your name contains 12 characters
 +
---------------------
 +
==> Sir Elton John <==
 +
Your name contains 14 characters
 +
---------------------
 +
==> Lady Gaga <==
 +
Your name contains 9 characters
 +
</source>
 +
|}
 +
<br /><br />
 +
<!-- ---------------------------------------------------------------------------------------------------- -->
 +
=Problem 8=
 +
<br />
 +
Copy the incomplete program below into IDLE, and edit it until its output is '''exactly''' the same as the one shown in the right column of the table below.  Be careful, as the Moodle testing program counts extra spaces or extra blank lines in your output as incorrect!
 +
 +
Make sure you click on '''evaluate''' in Moodle to make sure your program receives a grade.
 +
 +
<br />
 +
{| class="wikitable" width="100%"
 +
! incomplete program
 +
! output
 +
|-
 +
|
 +
<source lang="python">
 +
# Homework 1, Problem 8
 +
 +
def greet2( person ):
 +
    print( person )
 +
    print()
 +
 +
for person in [ "Emily", "Jo" ]:
 +
    greet2( person )
 +
 +
</source>
 +
|
 +
<source lang="text">
 +
Lujun is a Smith College student
 +
 +
Emily is a Smith College student
 +
 +
Jo is a Smith College student
 +
 +
 +
</source>
 +
|}
 +
<br /><br />
 +
<!-- ---------------------------------------------------------------------------------------------------- -->
 +
=Problem 9=
 +
<br />
 +
Copy the incomplete program below into IDLE, and edit it until its output is '''exactly''' the same as the one shown in the right column of the table below.  Be careful, as the Moodle testing program counts extra spaces or extra blank lines in your output as incorrect!
 +
 +
Make sure you click on '''evaluate''' in Moodle to make sure your program receives a grade.
 +
 +
<br />
 +
{| class="wikitable" width="100%"
 +
! incomplete program
 +
! output
 +
|-
 +
|
 +
<source lang="python">
 +
# Homework 1, Problem 9
 +
 +
for degreesF in [ -10, 10, 20, 30, 32, 40, 50 ]:
 +
    degreesC = (degreesF - 32) * 5 / 9
 +
    print( degreesF, "is", round( degreesC ) )
 +
</source>
 +
|
 +
<source lang="text">
 +
-10 Fahrenheit is -23 Celsius
 +
0 Fahrenheit is -18 Celsius
 +
10 Fahrenheit is -12 Celsius
 +
20 Fahrenheit is -7 Celsius
 +
30 Fahrenheit is -1 Celsius
 +
32 Fahrenheit is 0 Celsius
 +
40 Fahrenheit is 4 Celsius
 +
50 Fahrenheit is 10 Celsius
 +
60 Fahrenheit is 16 Celsius
 +
 +
</source>
 +
|}
 +
<br /><br />
 +
<!-- ---------------------------------------------------------------------------------------------------- -->
 +
=Problem 10=
 +
<br />
 +
Copy the incomplete program below into IDLE, and edit it until its output is '''exactly''' the same as the one shown in the right column of the table below.  Be careful, as the Moodle testing program counts extra spaces or extra blank lines in your output as incorrect!
 +
 +
Make sure you click on '''evaluate''' in Moodle to make sure your program receives a grade.
 +
 +
<br />
 +
{| class="wikitable" width="100%"
 +
! incomplete program
 +
! output
 +
|-
 +
|
 +
<source lang="python">
 +
# Homework 1, Problem 10
 +
 +
def printBar( length ):
 +
    print( "-+" * length )
 +
 +
for length in [10,9,8,7,6,5,4,3,2,1]:
 +
    printBar( length )
 +
 +
</source>
 +
|
 +
<source lang="text">
 +
+-
 +
+-+-
 +
+-+-+-
 +
+-+-+-+-
 +
+-+-+-+-+-
 +
+-+-+-+-+-+-
 +
+-+-+-+-+-+-+-
 +
+-+-+-+-+-+-+-+-
 +
+-+-+-+-+-+-+-+-+-
 +
+-+-+-+-+-+-+-+-+-+-
 +
</source>
 +
|}
 +
<br />
 +
 +
<br />
 +
<br />
 +
<br />
 +
<br />
 +
<br />
 +
<br />
 +
<br />
 +
<br />
 +
<br />
 +
<br />
 +
[[Category:CSC111]][[Category:Homework]][[Category:Python]]

Revision as of 15:50, 25 January 2015

--D. Thiebaut (talk) 14:45, 25 January 2015 (EST)



In this assignment, each problem requires you to edit a program that is partly written, and available on Moodle, so that the output of your edited program matches exactly the output specified in the problem. There may be many different ways to edit a program to make it output the one specified in the problem. In general, if you have a choice between several modifications, pick the one that is the simplest. Do not try to rewrite the program, but keep its structure. It is acceptable to add new statements in some problems. You must evaluate each program on Moodle to receive a grade for it. Make sure you evaluate your programs before the deadline, otherwise you will not receive a grade. Remember that no extensions are given in this class!

Problem #1


Edit the program of the HW1 P1 section on Moodle, so that its output becomes:

incomplete program output
# Homework 1, Problem 1
# edit the statements below (some of them are incomplete) so that the output
# is the one stated in Homework #1, Problem #1


age = 
name = "Alex"
year = 2015

print( "--", year )
print( name, "is", "and was born in" )
-- 2015 --
Alex is 20 years old, and was born in 1995
Alex will be 25 in 2020.


Make sure you evaluate the program and receive a grade for it, otherwise your work will not be counted toward the homework grade!

Problem #2


Edit the program of the HW1 P2 section on Moodle, so that its output becomes:

incomplete program output
# Homework 1, Problem 2

college = "Smith College"
bar = "-" * len( college )
name = "Fiona"
print( bar )
print( college )
-------------
Smith College
Fiona
-------------


Make sure you evaluate the program and receive a grade for it, otherwise your work will not be counted toward the homework grade!

Problem #3


Be sure to read Chapter 1, Section 6 in Zelle before editing the program of the HW1 P3 section on Moodle, so that its output becomes:

incomplete program output
# Homework 1, Problem 3 (read Section 1.6 in Zelle)

def greet( person ):
    print( person )
    print( "How are you?" )

greet( "John" )
greet( "Emily" )
greet( "Lujun" )
Hello John
How are you?
Hello Emily
How are you?
Hello Lujun
How are you?


Make sure you evaluate the program and receive a grade for it, otherwise your work will not be counted toward the homework grade!

Problem #4


Edit the program of the HW1 P4 section on Moodle, so that its output becomes the one shown below:

incomplete program output
# Homework 1, Problem 4 (read Section 1.6 in Zelle)

def greetBar( person ):
    bar = "---------------------"
    print( bar )
    print( person )

greetBar( "Lujun" )
greetBar( "Emily" )
greetBar( "John" )
---------------------
Hello John
How are you?
---------------------
Hello Emily
How are you?
---------------------
Hello Lujun
How are you?



Problem #5


Copy the incomplete program below into IDLE, and edit it until its output is exactly the same as the one shown in the right column of the table below. Be careful, as the Moodle testing program counts extra spaces or extra blank lines in your output as incorrect!

Make sure you click on evaluate in Moodle to make sure your program receives a grade.

incomplete program output
# Homework 1, Problem 5

def greetLength( person ):
    bar = "---------------------"
    print( bar )
    noChars = len( person )
    print( "==>", person )
    print( "Your name contains", noChars)

greetLength( "John" )
greetLength( "Emily" )
---------------------
==> John <==
Your name contains 4 characters
---------------------
==> Emily <==
Your name contains 5 characters
---------------------
==> Jo <==
Your name contains 2 characters


Problem 6


Copy the incomplete program below into IDLE, and edit it until its output is exactly the same as the one shown in the right column of the table below. Be careful, as the Moodle testing program counts extra spaces or extra blank lines in your output as incorrect!

Make sure you click on evaluate in Moodle to make sure your program receives a grade.


incomplete program output
# Homework 1, Problem 
# Homework 1, Problem 6

def greetLength( person ):
    bar = "---------------------"
    print( bar )
    print( "Hello", person )

greetLength( "John" )
greetLength( "Emily" )
greetLength( "Jo" )
---------------------
Hello John how are you?
---------------------
Hello Emily how are you?
---------------------
Hello Jo how are you?



Problem 7


Copy the incomplete program below into IDLE, and edit it until its output is exactly the same as the one shown in the right column of the table below. Be careful, as the Moodle testing program counts extra spaces or extra blank lines in your output as incorrect!

Make sure you click on evaluate in Moodle to make sure your program receives a grade.


incomplete program output
# Homework 1, Problem 7

person1 = "Maria Callas"
person2 = "Sir Elton John"
person3 = "Lady Gaga"

def greetLength( person ):
    bar = "---------------------"
    print( bar )
    noChars = len( person )
    print( person, "<==" )
    print(  noChars, "characters" )

greetLength( person2 )
greetLength( person2 )
greetLength( person2 )
---------------------
==> Maria Callas <==
Your name contains 12 characters
---------------------
==> Sir Elton John <==
Your name contains 14 characters
---------------------
==> Lady Gaga <==
Your name contains 9 characters



Problem 8


Copy the incomplete program below into IDLE, and edit it until its output is exactly the same as the one shown in the right column of the table below. Be careful, as the Moodle testing program counts extra spaces or extra blank lines in your output as incorrect!

Make sure you click on evaluate in Moodle to make sure your program receives a grade.


incomplete program output
# Homework 1, Problem 8

def greet2( person ):
    print( person )
    print()

for person in [ "Emily", "Jo" ]:
    greet2( person )
Lujun is a Smith College student

Emily is a Smith College student

Jo is a Smith College student



Problem 9


Copy the incomplete program below into IDLE, and edit it until its output is exactly the same as the one shown in the right column of the table below. Be careful, as the Moodle testing program counts extra spaces or extra blank lines in your output as incorrect!

Make sure you click on evaluate in Moodle to make sure your program receives a grade.


incomplete program output
# Homework 1, Problem 9

for degreesF in [ -10, 10, 20, 30, 32, 40, 50 ]:
    degreesC = (degreesF - 32) * 5 / 9
    print( degreesF, "is", round( degreesC ) )
-10 Fahrenheit is -23 Celsius
0 Fahrenheit is -18 Celsius
10 Fahrenheit is -12 Celsius
20 Fahrenheit is -7 Celsius
30 Fahrenheit is -1 Celsius
32 Fahrenheit is 0 Celsius
40 Fahrenheit is 4 Celsius
50 Fahrenheit is 10 Celsius
60 Fahrenheit is 16 Celsius



Problem 10


Copy the incomplete program below into IDLE, and edit it until its output is exactly the same as the one shown in the right column of the table below. Be careful, as the Moodle testing program counts extra spaces or extra blank lines in your output as incorrect!

Make sure you click on evaluate in Moodle to make sure your program receives a grade.


incomplete program output
# Homework 1, Problem 10

def printBar( length ):
    print( "-+" * length )

for length in [10,9,8,7,6,5,4,3,2,1]:
    printBar( length )
+-
+-+-
+-+-+-
+-+-+-+-
+-+-+-+-+-
+-+-+-+-+-+-
+-+-+-+-+-+-+-
+-+-+-+-+-+-+-+-
+-+-+-+-+-+-+-+-+-
+-+-+-+-+-+-+-+-+-+-