Difference between revisions of "CSC111 Homework 1 2018"

From dftwiki3
Jump to: navigation, search
(Problem 5)
(Problem 6)
Line 265: Line 265:
 
<!-- ---------------------------------------------------------------------------------------------------- -->
 
<!-- ---------------------------------------------------------------------------------------------------- -->
  
=Problem 6=
+
=Problem #6=
 
<br />
 
<br />
 
Open IDLE on your computer and type in the incomplete program shown below.  Save it as '''hw1_6.py'''.  Modify it until you get it to show the output shown in the second column, below.  When you are satisfied your program runs correctly, submit it to Moodle, in the HW 1 P 6 section.
 
Open IDLE on your computer and type in the incomplete program shown below.  Save it as '''hw1_6.py'''.  Modify it until you get it to show the output shown in the second column, below.  When you are satisfied your program runs correctly, submit it to Moodle, in the HW 1 P 6 section.

Revision as of 21:20, 24 January 2018

D. Thiebaut (talk) 15:01, 17 January 2018 (EST)


This homework is due on Thursday Feb 8th, at 11:55 p.m. The quiz part of the assignment should be done individually. For the programming part of the assignment, you should find a partner and work in pair, and use the pair-programming approach. You may want to work with your lab partner, if the two of you have a good schedule.


Quiz


Please go to the CSC111 page on Moodle and answer the questions in the "Quiz" section for Week 1. The questions refer to Chapter 1 in the Zelle textbook, and to the article on pair programming.

Programming


Each problem below requires you to copy an incomplete program into IDLE, and then edit it so that the output of your edited program matches exactly the output specified in the problem. You will submit your programs for this assignment in the CSC111 section of your Moodle account.

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 possible 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 can click on the evaluate button to see whether your program is correct or not. The evaluate feature will be available for the first half of the semester.

You should work as a pair on this assignment, and submit your program on Moodle twice, once for each member of the pair. For example, if Emily and Sarah work as a pair, they will create the program together on one computer. When the program runs well, Sarah will connect to her Moodle account, and submit the program in the area specific to this assignment, and then Emily will connect to her Moodle account and do the same.


Grading


Moodle uses numbers to grade programs. These numbers are translated into letters using the following scale:

  • 100.00 - 93.00: A
  • 92.99 - 90.00: A-
  • 89.99 - 87.00: B+
  • 86.99 - 83.00: B
  • 82.99 - 80.00: B-
  • 79.99 - 77.00: C+
  • 76.99 - 73.00: C
  • 72.99 - 70.00: C-
  • 69.99 - 67.00: D+
  • 66.99 - 60.00: D
  • 59.99 - 0.00: F


Problem #1


Open IDLE on your computer and create a new program called hw1_1.py. In the IDLE edit window, type the incomplete program shown below. Modify it until you get it to show the output shown in the second column, below. When you are satisfied your program runs correctly, submit it to Moodle, in the HW 1 P 1 section:

Incomplete program Output
# hw1_1.py
# Homework 1, Problem 1
# Name of pair partner #1
# Name of pair partner #2

age = 1  # you may want to change this number
name = "Alex"
year = 2018

print( "++", year )
print( name, "is", "and was born in" )
++ 2018 ++
Alex is 20 years old and was born in 1998
Alex will be 25 in 2020


You click on run to verify that your program works. Click on evaluate to see if it outputs the correct information.
Possible grades: A, A- or B.

Problem #2


Open IDLE on your computer and create a new program called hw1_2.py. In the IDLE window, type in the incomplete program shown below. Modify it until you get it to show the output shown in the second column, below. When you are satisfied your program runs correctly, submit it to Moodle, in the HW 1 P 2 section:

Incomplete program Output
# hw1_2.py
# Homework 1, Problem 2
# Name of pair partner #1
# Name of pair partner #2

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



Possible grades: A, A- or B.

Problem #3


Be sure to read Chapter 1, Section 6 in Zelle before starting. Then, open IDLE on your computer, create a program called hw1_3.py, and type in the incomplete program shown below. Modify it until you get it to show the output shown in the second column, below. When you are satisfied your program runs correctly, submit it to Moodle, in the HW 1 PB 3 section:

Incomplete program Output
# hw1_3.py
# Homework 1, Problem 3
# Name of pair partner #1
# Name of pair partner #2

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

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



Possible grades: A, A- or B.

Problem #4


Open IDLE on your computer and type in the incomplete program shown below. Save it in a file called hw1_4.py. Modify it until you get it to show the output shown in the second column, below. When you are satisfied your program runs correctly, submit it to Moodle, in the HW 1 PB 4 section:

Incomplete program Output
# hw1_4.py
# Homework 1, Problem 4
# Name of pair partner #1
# Name of pair partner #2

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?



Possible grades: A, A- or B.

Problem #5


Open IDLE on your computer and type in the incomplete program shown below. Save it as hw1_5.py. Modify it until you get it to show the output shown in the second column, below. When you are satisfied your program runs correctly, submit it to Moodle, in the HW 1 P 5 section. 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
# hw1_5.py
# Homework 1, Problem 5
# Name of pair partner #1
# Name of pair partner #2

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?



Possible grades: A, A- or B.

Problem #6


Open IDLE on your computer and type in the incomplete program shown below. Save it as hw1_6.py. Modify it until you get it to show the output shown in the second column, below. When you are satisfied your program runs correctly, submit it to Moodle, in the HW 1 P 6 section.

Be careful, as the Moodle testing program may count extra spaces or extra blank lines in your output as incorrect!


Incomplete program Output
# hw1_6.py
# Homework 1, Problem 6
# Name of pair partner #1
# Name of pair partner #2

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



Possible grades: A, A- or B.


<showafterdate after="20180209 00:00" before="20180601 00:00">

Solution Programs


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

print("\n\n==================== 1 ========================\n\n" )

# hw1_1.py
# Homework 1, Problem 1
# Name of pair partner #1
# Name of pair partner #2

age = 20
name = "Alex"
year = 2015

print( "--", year, "--" )
print( name, "is", age, "years old and was born in", year-age )
print( name, "will be", 2020-2015 + age, "in 2020" )


print("\n\n==================== 2 ========================\n\n" )

# Homework 1, Problem 2

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

print("\n\n==================== 3 ========================\n\n" )

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

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

greet( "John" )
greet( "Emily" )
greet( "Lujun" )

print("\n\n==================== 4 ========================\n\n" )

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

def greetBar( person ):
    bar = "---------------------"
    print( bar )
    print( "Hello", person )
    print( "How are you?" )

greetBar( "John" )
greetBar( "Emily" )
greetBar( "Lujun" )


print("\n\n==================== 5 ========================\n\n" )

# Homework 1, Problem 5

def greetLength( person ):
    bar = "---------------------"
    print( bar )
    noChars = len( person )
    print( "Hello", person, "how are you?" )

greetLength( "John" )
greetLength( "Emily" )
greetLength( "Jo" )

print("\n\n==================== 6 ========================\n\n" )

# Homework 1, Problem 6

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

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

greetLength( person1 )
greetLength( person2 )
greetLength( person3 )

</showafterdate>