יום שני, 13 בפברואר 2012

Programming in Python Chapters 3+4

3.2 Exercises

1. r=5
p=3.141592
area=p*r**2
2.10
3.name, d7, 2x, first_name, lastName, Amt
4.firstName='Tal'
lastName='Zilkha'
print (firstName+' '+lastName)
5.5 and 3
6.5, error, 'five', 4
7.
def pow4(x):
    return**4
8.+++++len = 5


3.3 Exercises

1. Local variables are for functions and global are variables which are not just for one function
2.??? how???
3.not sure?
4.one returns 50 the other returns 25


3.4 Exercises

1.
def f(x,y):
 return (x+' '+y)
2.I can do this.
3.
def rightJustify(s,w):
 return ((w-len(s))*' '+s)
4. dont get it
5. returns 2
6.21?, nothing
7.???
8.len(0), len((0))


3.5 Exercises

1.
def mystery(x,y):
  return x//y
2.
def mystery(x,y):
  return x/y
gives you division
3.
def test(a,b):
  return (a+b)/2
4.b=1 a=2
5.nope
6.don't get it
7.
from math import sqrt
def quadtratic(a,b,c):
  return (((-b+sqrt(b**2-4*a*c))/(2*a), ((-b-sqrt(b**2-4*a*c))/(2*a))
8.
9.


4.2 Exercises

1.add 2 starting from 1. 1+2n
2.1 over 2 times 3n
3.1,2,4,8,16 (1*2n), 1,4,16 (1*4n)
4.36
5.1:3
6.1+11k=1024
k=93
93(21)+1=1954
7. the difference is the same...
8. does it want me to give an example or prove it? not sure how to prove it
9.they can be. multiplication by 1 (addition by 0)
10. limit is 1
11. at 1?
12.1


4.3 Exercises

1. the middle term
2.what?
3.1
4.okay.
5.huh?
6.6543210
7.2^n-n
8.?


4.4 Exercises

1.1
2.yes? to 1/100?
3.??
4.less than 1 but greater than 0
5.2, i think, guessing here
6.i think at 2, not sure
7.there is a limit on the area and the perimeter i believe


4.5 Exercises

1.

יום שלישי, 7 בפברואר 2012

Programming in Python Chapters 1+2

1.2 Exercises

1.empty set, {a}, {a,b}, {b}
2.7, 25(?), n!+1(?)
3.f(x)=2x for 0<x<6
4.Can't really think of one, but I'm pretty sure it's possible.
5.Same thing ^^
6.f(x)=x%3
7.f(A)= ???
8.uh?
9.f(x)= if even -1 else return?
10.return all 1 lengthed substrings...
11.??
12.f(x)=1/x

1.3 Exercises

1.all reals except 2, range all reals except 0
2.domain all reals equal to or more than -1, range all positive reals
3.domain from -1 to 1, range all positive reals
4. domain from 100 to 999 (900 elements), range from 1 to 27 (27 elements)
5.f(x)=xsquared +1
6.f(x)=x??
7.what do you mean?
8.recursive; if f(x) isnt between -1 and 1 then f(x/10)
9.1,2
10.too-much-ahh...

1.4 Exercises

1.power, !
2.
c<-1
result<-0
while c<n
    result+=c
return result
3.
p<-0
r<-0
while n>m
  p+=1
  m-=n
r<-m
4.
result<-1
z<-0
while z<n
  result*=n
return result
5.
p<-0
result<-0
while result<=n
   result*=2
   p++
return p-1
6.
compare letters, then lengths.

1.5 Exercises

1.ITS MOD!!!!!.......
2.
def incrementByOne(n):
 return n+1
3.absolute value...
4.
def sum1ToN(n):
   return ((n+!)*n/2)
5.
def reciprocal(x)
  return 1/x
6.12,11
7.No.
8.it multiplies the string.
9.
def imSickOfWorkingIWantToSleep(n):
  return n[0]
10.returns first character
11. gives the appropriate functions...
12. 0,3
13.
def sum1ToN(n):
   return sum(range(n))+n
14.
def numDigits(n):
k=1
j=10
while j<k:
    j*=10
    k+=1
return k

2.2 Exercises

1. I can't.
2. D
3.234,375
4.4,8,256
5.ASCII has 128 characters. 1 byte is enough. 7bits is exact
6.??
7.BX is 15 and AX is 6. not really sure what this code computes though, maybe turns things into hexa from deci?
8.uhh I don't know assembly that well...
9.^^^

2.3 Exercises

1.Syntax which is uneeded
2.Yes they work
3.returns 4
4.power function
5.connectes them
6.121212, it repeats the string
7.order of operations
8.(x-2)**3+3x
9.function than other external operations
10.after product and quotients

2.4 Exercises

1.????
2.def, return, while
3.need colon and return is capitalized
4.
One is better than
none; two is better than one
5.Python is #1
6.not sure.
7.
def firstLast(s):
    return (s[0]+s[-1])
8.
def triangle(s):
    print (5*s/3*s/s)


cool.