Difference between revisions of "HTTLACS: Ch 2 Exercises"
From WLCS
(Created page with "'''Directions:''' # Open a text editor (Applications->Accessories->gEdit Text Editor) # Put your name at the top # Save the file as YOURLASTNAME_ch2.txt # Complete the exercises ...") |
|||
(8 intermediate revisions by the same user not shown) | |||
Line 3: | Line 3: | ||
# Put your name at the top | # Put your name at the top | ||
# Save the file as YOURLASTNAME_ch2.txt | # Save the file as YOURLASTNAME_ch2.txt | ||
− | # Complete the exercises below in this file | + | # Complete the exercises below in this file. If you use DrPython, then be sure to copy your code back into this file |
+ | # Be sure to number each of your answers!! | ||
+ | |||
+ | '''References:''' | ||
+ | * [http://openbookproject.net/thinkcs/python/english2e/ch02.html How to Think Like a Computer Scientist: Chapter 2] | ||
'''Exercises:''' | '''Exercises:''' | ||
+ | # Try the following code in a program: '''print n = 7''' | ||
+ | #* The above should crash, change it to two lines of code so that you can '''print n''' and it works | ||
+ | # Take the sentence: '''All work and no play makes Jack a dull boy.''' Store each word in a separate variable, then print out the sentence on one line using print. | ||
+ | #* Example: a = "All" | ||
+ | # Add parenthesis to the expression 6 * 1 - 2 to change its value from 4 to -6. | ||
+ | # Prompt the user for a number and store it in a variable named '''x'''. Print out the square of x | ||
+ | # Prompt the user for a noun, verb, and adjective, storing them each in a variable | ||
+ | #* You should then print out the following sentence "The NOUN VERB in ADJECTIVE pants" and NOUN, VERB, ADJECTIVE are variables | ||
+ | # Take the following code: | ||
+ | |||
+ | <source lang="Python"> | ||
+ | print "Hello" | ||
+ | print "Washington-Lee" | ||
+ | print "Generals" | ||
+ | </source> | ||
+ | |||
+ | and comment out (#) the '''print "Washington-Lee" ''' so that it does not run. | ||
'''Submit:''' | '''Submit:''' | ||
* Submit the file to [http://wlhs.schoolweblockers.com/ School Web Lockers] | * Submit the file to [http://wlhs.schoolweblockers.com/ School Web Lockers] |
Latest revision as of 09:27, 12 October 2010
Directions:
- Open a text editor (Applications->Accessories->gEdit Text Editor)
- Put your name at the top
- Save the file as YOURLASTNAME_ch2.txt
- Complete the exercises below in this file. If you use DrPython, then be sure to copy your code back into this file
- Be sure to number each of your answers!!
References:
Exercises:
- Try the following code in a program: print n = 7
- The above should crash, change it to two lines of code so that you can print n and it works
- Take the sentence: All work and no play makes Jack a dull boy. Store each word in a separate variable, then print out the sentence on one line using print.
- Example: a = "All"
- Add parenthesis to the expression 6 * 1 - 2 to change its value from 4 to -6.
- Prompt the user for a number and store it in a variable named x. Print out the square of x
- Prompt the user for a noun, verb, and adjective, storing them each in a variable
- You should then print out the following sentence "The NOUN VERB in ADJECTIVE pants" and NOUN, VERB, ADJECTIVE are variables
- Take the following code:
print "Hello"
print "Washington-Lee"
print "Generals"
and comment out (#) the print "Washington-Lee" so that it does not run.
Submit:
- Submit the file to School Web Lockers