יום שלישי, 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.

אין תגובות:

הוסף רשומת תגובה