File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ #!/usr/bin/env python
2+
3+ """
4+ CodingBat Examples:
5+ """
6+
7+ ##Warmup-1 > sleep_in
8+
9+ #sample 1:
10+ def sleep_in (weekday , vacation ):
11+ if vacation :
12+ return True
13+ if not weekday :
14+ return True
15+ return False
16+
17+ #sample 2:
18+ def sleep_in (weekday , vacation ):
19+ if not weekday or vacation :
20+ return True
21+ else :
22+ return False
23+
24+ #sample 3:
25+ def sleep_in (weekday , vacation ):
26+ # parentheses not required...
27+ return (not weekday ) or vacation
28+
29+ ## Warmup-1 > diff21:
30+
31+ def diff21 (n ):
32+ result = n - 21
33+ if result > 0 :
34+ return result * 2
35+ else :
36+ return - result
37+
38+ ## Warmup-1 > makes10:
39+
40+ def makes10 (a , b ):
41+ return a == 10 or b == 10 or a + b == 10
42+
Original file line number Diff line number Diff line change 1+ Students:
2+
3+ Languages:
4+
5+ shell **
6+ perl *
7+ C **
8+ xml
9+ multimod
10+ assembly
11+ cobol
12+ c++
13+ c#
14+ Basic
15+ Python
16+ Fortran
17+ Visual Basic
18+ Javascript
19+ Pascal
20+ powershell
21+ DOS batch
22+ PHP
Original file line number Diff line number Diff line change 11#!/usr/bin/env python
22
33print "Hello!"
4+
5+ def test_fun (x ,y ,z ):
6+ summ = x + y + z
7+
8+ return summ
9+
Original file line number Diff line number Diff line change 1+ week 2: Cliff
2+ week 2: Myke
3+ week 3: Bill
4+ week 3: Joshua
5+ week 4: David
6+ week 4: Rob
7+ week 5: Drew
8+ week 5: Phillip
9+ week 6: Brett
10+ week 6: Matt
11+ week 7: Jeffrey
12+ week 7: Scott
13+ week 8: Peter
14+ week 9: Chris
15+ week 10: John
Original file line number Diff line number Diff line change 1- Fred A.
2- Fred B.
3- Nancy C.
4- Nancy D.
5- Mary E.
6- Mary F.
7- Fred G.
8- Fred H.
9- Nancy I.
10- Nancy J.
11- Mary K.
12- Mary L.
1+ Bill
2+ Brett
3+ Chris
4+ Cliff
5+ David
6+ Drew
7+ Jeffrey
8+ John
9+ Joshua
10+ Matt
11+ Myke
12+ Peter
13+ Phillip
14+ Rob
15+ Scott
16+
Original file line number Diff line number Diff line change 1+ #!/usr/bin/env python
2+
3+ def factorial (n ):
4+ """
5+ copmutes the factorial of n
6+
7+ param: n -- an integer to copute the factorial of
8+
9+ returns: the factorial of n
10+ """
11+ f = float (n )
12+ n = int (n )
13+ if n != f :
14+ print "factorial only works for integers:" ,
15+ return None
16+ if n == 0 :
17+ return 1
18+ else :
19+ return n * factorial (n - 1 )
20+
21+
22+ print "the factorial of 0 is:" , factorial (0 )
23+ print "the factorial of 1 is:" , factorial (1 )
24+ print "the factorial of 2 is:" , factorial (2 )
25+ print "the factorial of 3 is:" , factorial (3 )
26+ print "the factorial of 4 is:" , factorial (4 )
27+
28+ print "the factorial of 983 is:" , factorial (983 )
29+
30+ #print "the factorial of 984 is:", factorial(984)
31+
32+ print "the factorial of 4L is:" , factorial (4L )
33+
34+ print "the factorial of 1.5 is:" , factorial (1.5 )
35+
36+ ## checking types: -- is instance
You can’t perform that action at this time.
0 commit comments