Difference between revisions of "CSC111 Homework 1 2015"
(→Problem 6) |
|||
(20 intermediate revisions by the same user not shown) | |||
Line 3: | Line 3: | ||
<br /> | <br /> | ||
<bluebox> | <bluebox> | ||
− | In this assignment | + | In this assignment is due on 2/3/15 at 11:55 p.m. |
+ | |||
+ | Each problem 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 find 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 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! | ||
+ | |||
+ | '''Grading''': The homework assignments count for a total of 40% of the final grade. Since there will be approximately 11 assignments this semester, each one will count for roughly 40/11 or 3.9% of the final grade. Homework 1 contains 10 problems; therefore each one counts for approximately 0.039% of the final grade. The programs are graded 0 or 100, depending on whether its output is exactly the one required, or not. | ||
</bluebox> | </bluebox> | ||
<br /> | <br /> | ||
Line 10: | Line 16: | ||
=Problem #1= | =Problem #1= | ||
<br /> | <br /> | ||
− | + | Open IDLE on your computer 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 P 1 section: | |
<br /> | <br /> | ||
{| class="wikitable" width="100%" | {| class="wikitable" width="100%" | ||
− | ! style="width: 60%;" | + | ! style="width: 60%;" | '''Incomplete program''' |
− | + | ! Output | |
− | ! | ||
|- | |- | ||
| | | | ||
<source lang="python"> | <source lang="python"> | ||
# Homework 1, Problem 1 | # Homework 1, Problem 1 | ||
− | |||
− | |||
− | |||
age = 1 | age = 1 | ||
Line 47: | Line 49: | ||
=Problem #2= | =Problem #2= | ||
<br /> | <br /> | ||
− | + | Open IDLE on your computer 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 P 2 section:<br /> | |
− | <br /> | ||
{| class="wikitable" width="100%" | {| class="wikitable" width="100%" | ||
− | ! | + | ! style="width: 60%;" | '''Incomplete program''' |
− | ! | + | ! Output |
|- | |- | ||
| | | | ||
Line 77: | Line 78: | ||
=Problem #3= | =Problem #3= | ||
<br /> | <br /> | ||
− | Be sure to read Chapter 1, Section 6 in Zelle before | + | Be sure to read Chapter 1, Section 6 in Zelle before starting. Then, open IDLE on your computer 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: |
<br /> | <br /> | ||
{| class="wikitable" width="100%" | {| class="wikitable" width="100%" | ||
− | ! | + | ! style="width: 60%;" | '''Incomplete program''' |
− | ! | + | ! Output |
|- | |- | ||
| | | | ||
Line 112: | Line 113: | ||
=Problem #4= | =Problem #4= | ||
<br /> | <br /> | ||
− | + | Open IDLE on your computer 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 4 section:<br /> | |
− | <br /> | ||
{| class="wikitable" width="100%" | {| class="wikitable" width="100%" | ||
− | ! | + | ! style="width: 60%;" | '''Incomplete program''' |
− | ! | + | ! Output |
|- | |- | ||
| | | | ||
Line 150: | Line 150: | ||
=Problem #5= | =Problem #5= | ||
<br /> | <br /> | ||
− | + | Open IDLE on your computer 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 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. | 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%" | ||
− | ! | + | ! style="width: 60%;" | '''Incomplete program''' |
− | ! | + | ! Output |
|- | |- | ||
| | | | ||
Line 188: | Line 190: | ||
<br /> | <br /> | ||
<!-- ---------------------------------------------------------------------------------------------------- --> | <!-- ---------------------------------------------------------------------------------------------------- --> | ||
+ | |||
=Problem 6= | =Problem 6= | ||
<br /> | <br /> | ||
− | + | Open IDLE on your computer 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 P 6 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. | Make sure you click on '''evaluate''' in Moodle to make sure your program receives a grade. | ||
Line 196: | Line 199: | ||
<br /> | <br /> | ||
{| class="wikitable" width="100%" | {| class="wikitable" width="100%" | ||
− | ! | + | ! style="width: 60%;" | '''Incomplete program''' |
− | ! | + | ! Output |
|- | |- | ||
| | | | ||
<source lang="python"> | <source lang="python"> | ||
− | |||
# Homework 1, Problem 6 | # Homework 1, Problem 6 | ||
Line 226: | Line 228: | ||
<br /> | <br /> | ||
<!-- ---------------------------------------------------------------------------------------------------- --> | <!-- ---------------------------------------------------------------------------------------------------- --> | ||
+ | |||
=Problem 7= | =Problem 7= | ||
<br /> | <br /> | ||
− | + | Open IDLE on your computer 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 P 7 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. | Make sure you click on '''evaluate''' in Moodle to make sure your program receives a grade. | ||
Line 234: | Line 239: | ||
<br /> | <br /> | ||
{| class="wikitable" width="100%" | {| class="wikitable" width="100%" | ||
− | ! | + | ! style="width: 60%;" | '''Incomplete program''' |
− | ! | + | ! Output |
|- | |- | ||
| | | | ||
Line 271: | Line 276: | ||
<br /><br /> | <br /><br /> | ||
<!-- ---------------------------------------------------------------------------------------------------- --> | <!-- ---------------------------------------------------------------------------------------------------- --> | ||
+ | |||
=Problem 8= | =Problem 8= | ||
<br /> | <br /> | ||
− | + | Open IDLE on your computer 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 P 8 section. | |
+ | |||
+ | Be careful, as the Moodle testing program counts extra spaces or extra blank lines in your output as incorrect! | ||
+ | |||
+ | Also, note that in this problem, there is a blank line printed after each non-blank output. | ||
Make sure you click on '''evaluate''' in Moodle to make sure your program receives a grade. | Make sure you click on '''evaluate''' in Moodle to make sure your program receives a grade. | ||
Line 279: | Line 289: | ||
<br /> | <br /> | ||
{| class="wikitable" width="100%" | {| class="wikitable" width="100%" | ||
− | ! | + | ! style="width: 60%;" | '''Incomplete program''' |
− | ! | + | ! Output |
|- | |- | ||
| | | | ||
Line 310: | Line 320: | ||
=Problem 9= | =Problem 9= | ||
<br /> | <br /> | ||
− | + | This problem corresponds to the HW1 P9 section on Moodle. | |
+ | |||
+ | Open IDLE on your computer 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 P 9 section. | ||
Make sure you click on '''evaluate''' in Moodle to make sure your program receives a grade. | Make sure you click on '''evaluate''' in Moodle to make sure your program receives a grade. | ||
Line 316: | Line 328: | ||
<br /> | <br /> | ||
{| class="wikitable" width="100%" | {| class="wikitable" width="100%" | ||
− | ! | + | ! style="width: 60%;" | '''Incomplete program''' |
− | ! | + | ! Output |
|- | |- | ||
| | | | ||
Line 343: | Line 355: | ||
<br /><br /> | <br /><br /> | ||
<!-- ---------------------------------------------------------------------------------------------------- --> | <!-- ---------------------------------------------------------------------------------------------------- --> | ||
+ | |||
=Problem 10= | =Problem 10= | ||
<br /> | <br /> | ||
− | + | Open IDLE on your computer 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 P 10 section. | |
Make sure you click on '''evaluate''' in Moodle to make sure your program receives a grade. | Make sure you click on '''evaluate''' in Moodle to make sure your program receives a grade. | ||
Line 351: | Line 364: | ||
<br /> | <br /> | ||
{| class="wikitable" width="100%" | {| class="wikitable" width="100%" | ||
− | ! | + | ! style="width: 60%;" | '''Incomplete program''' |
− | ! | + | ! Output |
|- | |- | ||
| | | | ||
Line 381: | Line 394: | ||
<br /> | <br /> | ||
+ | <showafterdate after="20150204 00:00" before="20150601 00:00"> | ||
+ | =Solution Programs= | ||
+ | <br /> | ||
+ | <source lang="python"> | ||
+ | |||
+ | # 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" ) | ||
+ | |||
+ | 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 - year + 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( "==>", person, "<==" ) | ||
+ | print( "Your name contains", noChars, "characters" ) | ||
+ | |||
+ | greetLength( "John" ) | ||
+ | greetLength( "Emily" ) | ||
+ | greetLength( "Jo" ) | ||
+ | |||
+ | print("\n\n==================== 6 ========================\n\n" ) | ||
+ | |||
+ | # Homework 1, Problem 6 | ||
+ | |||
+ | def greetLength( person ): | ||
+ | bar = "---------------------" | ||
+ | print( bar ) | ||
+ | noChars = len( person ) | ||
+ | print( "Hello", person, "how are you?" ) | ||
+ | |||
+ | greetLength( "John" ) | ||
+ | greetLength( "Emily" ) | ||
+ | greetLength( "Jo" ) | ||
+ | |||
+ | print("\n\n==================== 7 ========================\n\n" ) | ||
+ | |||
+ | # 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( "Your name contains", noChars, "characters" ) | ||
+ | |||
+ | greetLength( person1 ) | ||
+ | greetLength( person2 ) | ||
+ | greetLength( person3 ) | ||
+ | |||
+ | print("\n\n==================== 8 ========================\n\n" ) | ||
+ | |||
+ | # Homework 1, Problem 8 | ||
+ | |||
+ | def greet2( person ): | ||
+ | print( person, "is a Smith College student" ) | ||
+ | print() | ||
+ | |||
+ | for person in [ "Lujun", "Emily", "Jo" ]: | ||
+ | greet2( person ) | ||
+ | |||
+ | |||
+ | print("\n\n==================== 9 ========================\n\n" ) | ||
+ | |||
+ | # Homework 1, Problem 9 | ||
+ | |||
+ | for degreesF in [ -10, 0, 10, 20, 30, 32, 40, 50, 60 ]: | ||
+ | degreesC = (degreesF - 32) * 5 / 9 | ||
+ | print( degreesF, "Fahrenheit is", round( degreesC ), "Celsius" ) | ||
+ | |||
+ | print("\n\n==================== 10 ========================\n\n" ) | ||
+ | |||
+ | # Homework 1, Problem 10 | ||
+ | |||
+ | def printBar( length ): | ||
+ | print( "+-" * length ) | ||
+ | |||
+ | for length in [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]: | ||
+ | printBar( length ) | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | </source> | ||
+ | </showafterdate> | ||
+ | <onlydft> | ||
+ | =VPL Modules for Testing= | ||
+ | ==Hw 1 P1== | ||
+ | <source lang="text"> | ||
+ | vpl_run.sh | ||
+ | 1 #! /bin/bash | ||
+ | 2 | ||
+ | 3 cat > vpl_execution <<EOF | ||
+ | 4 #! /bin/bash | ||
+ | 5 | ||
+ | 6 prog=hw1p1.py | ||
+ | 7 python=/usr/local/bin/python3.4 | ||
+ | 8 #python=/usr/bin/python3 | ||
+ | 9 | ||
+ | 10 \$python \$prog | sed 's/ \./\./g' | ||
+ | 11 | ||
+ | 12 EOF | ||
+ | 13 | ||
+ | 14 chmod +x vpl_execution | ||
+ | vpl_debug.sh | ||
+ | vpl_evaluate.sh | ||
+ | vpl_evaluate.cases | ||
+ | 1 Case = Test 1 | ||
+ | 2 output = "-- 2015 -- | ||
+ | 3 Alex is 20 years old, and was born in 1995 | ||
+ | 4 Alex will be 25 in 2020. | ||
+ | 5 " | ||
+ | </source> | ||
+ | ==Hw 1 P2== | ||
+ | <source lang="text"> | ||
+ | vpl_run.sh | ||
+ | 1 #! /bin/bash | ||
+ | 2 | ||
+ | 3 cat > vpl_execution <<EOF | ||
+ | 4 #! /bin/bash | ||
+ | 5 | ||
+ | 6 prog=hw1p2.py | ||
+ | 7 python=/usr/local/bin/python3.4 | ||
+ | 8 | ||
+ | 9 \$python \$prog | ||
+ | 10 | ||
+ | 11 EOF | ||
+ | 12 | ||
+ | 13 chmod +x vpl_execution | ||
+ | vpl_debug.sh | ||
+ | vpl_evaluate.sh | ||
+ | vpl_evaluate.cases | ||
+ | 1 Case = Test 1 | ||
+ | 2 output = "------------- | ||
+ | 3 Smith College | ||
+ | 4 Fiona | ||
+ | 5 ------------- | ||
+ | 6 " | ||
+ | </source> | ||
+ | ==Hw 1 P3== | ||
+ | <source lang="text"> | ||
+ | vpl_run.sh | ||
+ | 1 #! /bin/bash | ||
+ | 2 | ||
+ | 3 cat > vpl_execution <<EOF | ||
+ | 4 #! /bin/bash | ||
+ | 5 | ||
+ | 6 prog=hw1p3.py | ||
+ | 7 python=/usr/local/bin/python3.4 | ||
+ | 8 | ||
+ | 9 \$python \$prog | ||
+ | 10 | ||
+ | 11 EOF | ||
+ | 12 | ||
+ | 13 chmod +x vpl_execution | ||
+ | vpl_debug.sh | ||
+ | vpl_evaluate.sh | ||
+ | vpl_evaluate.cases | ||
+ | 1 Case = Test 1 | ||
+ | 2 output = "Hello John | ||
+ | 3 How are you? | ||
+ | 4 Hello Emily | ||
+ | 5 How are you? | ||
+ | 6 Hello Lujun | ||
+ | 7 How are you? | ||
+ | 8 " | ||
+ | </source> | ||
+ | ==Hw 1 P4== | ||
+ | <source lang="text"> | ||
+ | vpl_run.sh | ||
+ | 1 #! /bin/bash | ||
+ | 2 | ||
+ | 3 cat > vpl_execution <<EOF | ||
+ | 4 #! /bin/bash | ||
+ | 5 | ||
+ | 6 prog=hw1p4.py | ||
+ | 7 python=/usr/local/bin/python3.4 | ||
+ | 8 | ||
+ | 9 \$python \$prog | ||
+ | 10 | ||
+ | 11 EOF | ||
+ | 12 | ||
+ | 13 chmod +x vpl_execution | ||
+ | vpl_debug.sh | ||
+ | vpl_evaluate.sh | ||
+ | vpl_evaluate.cases | ||
+ | 1 Case = Test 1 | ||
+ | 2 output = "--------------------- | ||
+ | 3 Hello John | ||
+ | 4 How are you? | ||
+ | 5 --------------------- | ||
+ | 6 Hello Emily | ||
+ | 7 How are you? | ||
+ | 8 --------------------- | ||
+ | 9 Hello Lujun | ||
+ | 10 How are you? | ||
+ | 11 " | ||
+ | </source> | ||
+ | ==Hw 1 P5== | ||
+ | <source lang="text"> | ||
+ | vpl_run.sh | ||
+ | 1 #! /bin/bash | ||
+ | 2 | ||
+ | 3 cat > vpl_execution <<EOF | ||
+ | 4 #! /bin/bash | ||
+ | 5 | ||
+ | 6 prog=hw1p5.py | ||
+ | 7 python=/usr/local/bin/python3.4 | ||
+ | 8 | ||
+ | 9 \$python \$prog | ||
+ | 10 | ||
+ | 11 EOF | ||
+ | 12 | ||
+ | 13 chmod +x vpl_execution | ||
+ | vpl_debug.sh | ||
+ | vpl_evaluate.sh | ||
+ | vpl_evaluate.cases | ||
+ | 1 Case = Test 1 | ||
+ | 2 output = "--------------------- | ||
+ | 3 ==> John <== | ||
+ | 4 Your name contains 4 characters | ||
+ | 5 --------------------- | ||
+ | 6 ==> Emily <== | ||
+ | 7 Your name contains 5 characters | ||
+ | 8 --------------------- | ||
+ | 9 ==> Jo <== | ||
+ | 10 Your name contains 2 characters | ||
+ | 11 " | ||
+ | </source> | ||
+ | ==Hw 1 P6== | ||
+ | <source lang="text"> | ||
+ | vpl_run.sh | ||
+ | 1 #! /bin/bash | ||
+ | 2 | ||
+ | 3 cat > vpl_execution <<EOF | ||
+ | 4 #! /bin/bash | ||
+ | 5 | ||
+ | 6 prog=hw1p6.py | ||
+ | 7 python=/usr/local/bin/python3.4 | ||
+ | 8 | ||
+ | 9 \$python \$prog | ||
+ | 10 | ||
+ | 11 EOF | ||
+ | 12 | ||
+ | 13 chmod +x vpl_execution | ||
+ | vpl_debug.sh | ||
+ | vpl_evaluate.sh | ||
+ | vpl_evaluate.cases | ||
+ | 1 Case = Test 1 | ||
+ | 2 output = "--------------------- | ||
+ | 3 Hello John how are you? | ||
+ | 4 --------------------- | ||
+ | 5 Hello Emily how are you? | ||
+ | 6 --------------------- | ||
+ | 7 Hello Jo how are you? | ||
+ | 8 " | ||
+ | </source> | ||
+ | ==Hw 1 P7== | ||
+ | <source lang="text"> | ||
+ | vpl_run.sh | ||
+ | 1 #! /bin/bash | ||
+ | 2 | ||
+ | 3 cat > vpl_execution <<EOF | ||
+ | 4 #! /bin/bash | ||
+ | 5 | ||
+ | 6 prog=hw1p7.py | ||
+ | 7 python=/usr/local/bin/python3.4 | ||
+ | 8 | ||
+ | 9 \$python \$prog | ||
+ | 10 | ||
+ | 11 EOF | ||
+ | 12 | ||
+ | 13 chmod +x vpl_execution | ||
+ | vpl_debug.sh | ||
+ | vpl_evaluate.sh | ||
+ | vpl_evaluate.cases | ||
+ | 1 Case = Test 1 | ||
+ | 2 output = "--------------------- | ||
+ | 3 ==> Maria Callas <== | ||
+ | 4 Your name contains 12 characters | ||
+ | 5 --------------------- | ||
+ | 6 ==> Sir Elton John <== | ||
+ | 7 Your name contains 14 characters | ||
+ | 8 --------------------- | ||
+ | 9 ==> Lady Gaga <== | ||
+ | 10 Your name contains 9 characters | ||
+ | 11 " | ||
+ | </source> | ||
+ | ==Hw 1 P8== | ||
+ | <source lang="text"> | ||
+ | vpl_run.sh | ||
+ | 1 #! /bin/bash | ||
+ | 2 | ||
+ | 3 cat > vpl_execution <<EOF | ||
+ | 4 #! /bin/bash | ||
+ | 5 | ||
+ | 6 prog=hw1p8.py | ||
+ | 7 python=/usr/local/bin/python3.4 | ||
+ | 8 | ||
+ | 9 \$python \$prog | ||
+ | 10 | ||
+ | 11 EOF | ||
+ | 12 | ||
+ | 13 chmod +x vpl_execution | ||
+ | vpl_debug.sh | ||
+ | vpl_evaluate.sh | ||
+ | vpl_evaluate.cases | ||
+ | 1 Case = Test 1 | ||
+ | 2 output = "Lujun is a Smith College student | ||
+ | 3 | ||
+ | 4 Emily is a Smith College student | ||
+ | 5 | ||
+ | 6 Jo is a Smith College student | ||
+ | 7 | ||
+ | 8 " | ||
+ | </source> | ||
+ | ==Hw 1 P9== | ||
+ | <source lang="text"> | ||
+ | vpl_run.sh | ||
+ | 1 #! /bin/bash | ||
+ | 2 | ||
+ | 3 cat > vpl_execution <<EOF | ||
+ | 4 #! /bin/bash | ||
+ | 5 | ||
+ | 6 prog=hw1p9.py | ||
+ | 7 python=/usr/local/bin/python3.4 | ||
+ | 8 | ||
+ | 9 \$python \$prog | ||
+ | 10 | ||
+ | 11 EOF | ||
+ | 12 | ||
+ | 13 chmod +x vpl_execution | ||
+ | vpl_debug.sh | ||
+ | vpl_evaluate.sh | ||
+ | vpl_evaluate.cases | ||
+ | 1 Case = Test 1 | ||
+ | 2 output = "-10 Fahrenheit is -23 Celsius | ||
+ | 3 0 Fahrenheit is -18 Celsius | ||
+ | 4 10 Fahrenheit is -12 Celsius | ||
+ | 5 20 Fahrenheit is -7 Celsius | ||
+ | 6 30 Fahrenheit is -1 Celsius | ||
+ | 7 32 Fahrenheit is 0 Celsius | ||
+ | 8 40 Fahrenheit is 4 Celsius | ||
+ | 9 50 Fahrenheit is 10 Celsius | ||
+ | 10 60 Fahrenheit is 16 Celsius | ||
+ | 11 " | ||
+ | </source> | ||
+ | ==Hw 1 P10== | ||
+ | <source lang="text"> | ||
+ | vpl_run.sh | ||
+ | 1 #! /bin/bash | ||
+ | 2 | ||
+ | 3 cat > vpl_execution <<EOF | ||
+ | 4 #! /bin/bash | ||
+ | 5 | ||
+ | 6 prog=hw1p10.py | ||
+ | 7 python=/usr/local/bin/python3.4 | ||
+ | 8 | ||
+ | 9 \$python \$prog | ||
+ | 10 | ||
+ | 11 EOF | ||
+ | 12 | ||
+ | 13 chmod +x vpl_execution | ||
+ | vpl_debug.sh | ||
+ | vpl_evaluate.sh | ||
+ | vpl_evaluate.cases | ||
+ | 1 Case = Test 1 | ||
+ | 2 output = "+- | ||
+ | 3 +-+- | ||
+ | 4 +-+-+- | ||
+ | 5 +-+-+-+- | ||
+ | 6 +-+-+-+-+- | ||
+ | 7 +-+-+-+-+-+- | ||
+ | 8 +-+-+-+-+-+-+- | ||
+ | 9 +-+-+-+-+-+-+-+- | ||
+ | 10 +-+-+-+-+-+-+-+-+- | ||
+ | 11 +-+-+-+-+-+-+-+-+-+- | ||
+ | 12 " | ||
+ | </source> | ||
<br /> | <br /> | ||
+ | </onlydft> | ||
<br /> | <br /> | ||
<br /> | <br /> |
Latest revision as of 06:28, 30 January 2015
--D. Thiebaut (talk) 14:45, 25 January 2015 (EST)
In this assignment is due on 2/3/15 at 11:55 p.m.
Each problem 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 find 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 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!
Grading: The homework assignments count for a total of 40% of the final grade. Since there will be approximately 11 assignments this semester, each one will count for roughly 40/11 or 3.9% of the final grade. Homework 1 contains 10 problems; therefore each one counts for approximately 0.039% of the final grade. The programs are graded 0 or 100, depending on whether its output is exactly the one required, or not.
Problem #1
Open IDLE on your computer 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 P 1 section:
Incomplete program | Output |
---|---|
# Homework 1, Problem 1
age = 1
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
Open IDLE on your computer 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 P 2 section:
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 starting. Then, open IDLE on your computer 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 |
---|---|
# 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
Open IDLE on your computer 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 4 section:
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
Open IDLE on your computer 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 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 |
---|---|
# 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
Open IDLE on your computer 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 P 6 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 |
---|---|
# 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
Open IDLE on your computer 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 P 7 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 |
---|---|
# 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
Open IDLE on your computer 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 P 8 section.
Be careful, as the Moodle testing program counts extra spaces or extra blank lines in your output as incorrect!
Also, note that in this problem, there is a blank line printed after each non-blank output.
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
This problem corresponds to the HW1 P9 section on Moodle.
Open IDLE on your computer 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 P 9 section.
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
Open IDLE on your computer 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 P 10 section.
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 )
|
+-
+-+-
+-+-+-
+-+-+-+-
+-+-+-+-+-
+-+-+-+-+-+-
+-+-+-+-+-+-+-
+-+-+-+-+-+-+-+-
+-+-+-+-+-+-+-+-+-
+-+-+-+-+-+-+-+-+-+-
|
<showafterdate after="20150204 00:00" before="20150601 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" )
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 - year + 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( "==>", person, "<==" )
print( "Your name contains", noChars, "characters" )
greetLength( "John" )
greetLength( "Emily" )
greetLength( "Jo" )
print("\n\n==================== 6 ========================\n\n" )
# Homework 1, Problem 6
def greetLength( person ):
bar = "---------------------"
print( bar )
noChars = len( person )
print( "Hello", person, "how are you?" )
greetLength( "John" )
greetLength( "Emily" )
greetLength( "Jo" )
print("\n\n==================== 7 ========================\n\n" )
# 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( "Your name contains", noChars, "characters" )
greetLength( person1 )
greetLength( person2 )
greetLength( person3 )
print("\n\n==================== 8 ========================\n\n" )
# Homework 1, Problem 8
def greet2( person ):
print( person, "is a Smith College student" )
print()
for person in [ "Lujun", "Emily", "Jo" ]:
greet2( person )
print("\n\n==================== 9 ========================\n\n" )
# Homework 1, Problem 9
for degreesF in [ -10, 0, 10, 20, 30, 32, 40, 50, 60 ]:
degreesC = (degreesF - 32) * 5 / 9
print( degreesF, "Fahrenheit is", round( degreesC ), "Celsius" )
print("\n\n==================== 10 ========================\n\n" )
# Homework 1, Problem 10
def printBar( length ):
print( "+-" * length )
for length in [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]:
printBar( length )
</showafterdate>