2014-03-03 + HW

posted Mar 3, 2014, 5:19 AM by Samuel Konstantinovich   [ updated Mar 3, 2014, 6:31 AM ]
Homework: Complete classwork1 and classwork2 if you didn't finish in class, PRINT a copy with your name, and period on the top as a comment (1 point for following directions, 2 points for the rest)

GOAL1: Review terminal Commands

As stated previously: Friday's exam covers everything we have learned so far. You are expected to be able to:
 Read/write/understand basic HTML, 
 Use the command line to work with your files, 
 Write basic functions in Python 

A few Python Functions will be discussed in class, along with good coding practices, and alternate solutions to some of the problems. Also you should try some Python tutorials and write more Python code to practice!

Since you had a lot more practice with HTML, ,the focus will be on the terminal commands.

Do now: Commands!
On paper use the following to help you write the commands 1-5:


(Do not assume your starting directory for this assignment)Write a sequence of terminal commands that would:
Assume you start in the directory /home/
1. create a thesis directory under /home/rweasley/
2. Copy the spells from harry potter, and put them in your newly created directory.
3. Delete the intro.txt file. 
4. rename that copied spell text file as 'superspells.txt'
(remember that renaming is the same as moving)
5. Run the command that changes your password.

ON THE COMPUTER:

Here are some things to do (ALL FROM THE TERMINAL)
1. Pick any HTML file on your website. Copy that file from your public_html directory to your desktop.
2. Make a directory on your desktop called tempfiles, then move the file you copied in step 1, into that new folder. 
3. Display the contents of that file on the terminal. 
4. cd into your home directory. Make a directory on your desktop from here called "ididit" without quotes. 


Goal2: converting to string, more practice with functions, formatting output.

If you want to use the sqrt function you need to:

import math

Then you can:

math.sqrt(VALUE)   for any integer or floating point (decimal) value.

CLASSWORK PART 1:

Write a function quadsolve that takes the coefficients of a quadratic equation a b and c, as well as a variable pos. When pos is +1 return the positive root of the equation, when pos is -1, return the negative root of the equation.
Examples of quadsolve(a,b,c,pos):
quadsolve(1,0,-1,1)→1
quadsolve(1,0,-1,-1)→-1
quadsolve(1,1,-6,1) →2
quadsolve(1,1,-6,-1)→-3


CLASSWORK PART 2:  

Lets format our output better!

showQuadSolve(A,B,C) → prints nicely formatted results

examples:

>>> showQuadSolve(1,2,1)

Positive root of 1x^2 + 2x + 1: -1.0

Negative root of 1x^2 + 2x + 1: -1.0

>>> showQuadSolve(1,-5,-50)

Positive root of 1x^2 + -5x + -50: 10.0

Negative root of 1x^2 + -5x + -50: -5.0

We can't just add the numbers to the string

print "the answer is " + 5 #this doesn't work (try it)

To do this you need to be able to combine variables with your string:

str(x) converts x to a string. This can be used when you want to combine numerical values with strings of text:

age=3

"I am" + str(age) + "years old"

or

"The root of " + str(A) + "x^2 . . . .. more text"

Comments