Complete the following function definitions, and write appropriate test calls.
ist_dreieck def (a, b, c):Here is an example usage follows for the leap year:
"" "returns True if defined by a, b and c is a valid triangle
" "" return True
ist_quadrat def (a, b, w) :
"" "returns True if a and b and the angle w is a
Square is defined "" "return True
def ist_schaltjahr (year):
" "" returns True if the given year is a leap year. Since 1582, the end is
Gregorian calendar, applicable to the following
rule for leap year determination:
In all years, the year is divisible by four, the 29th
February, a leap day and so this year is
leap year.
An exception, however, the full century in 1700,
1800, 1900, etc., also called secular years. Of these, only get those
a leap, that year is divisible by 400 is
. Every fourth year is thus a secular leap year. .
For all years \u0026lt;= 1582, the function returns False, because since the
leap year is not defined, otherwise apply the above rule "" "
return False
def fib (n):
" "" returns the Fibonacci number for n . The numbers are defined as follows:
fib (0) -> 0
fib (1) -> 1
fib (2) -> 1
fib (3) -> 2
fib (4) -> , 3
fib (5) -> 5
fib (6) -> 8
...
fib (10) -> 55
...
fib (15) -> 610 "" "return 1
def fibtab (s):
" "" creates a table of Fibonacci numbers are up as inclusive n.
fibtab (10) from the following:
[0, 1, 1, 2 , 3, 5, 8]
or fibtab (100):
[0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]
Note
use as line break, "in print, so
print (value, end = ',')
except of course the last value, here is"] "is required.
"" "
print (" [0, 1, 1, 2, 3, 5, 8] ") def
sum_3_5 (max):
" ""
frame sum of multiples of 3 and 5 is less than max.
provides example sum_3_5 (10) 23 because
the multiples of 3 \u0026lt;10 are
3 + 6 + 9 = 18
the multiples of 5 \u0026lt;10 are
5
18 + 5 = 23
sum_3_5 (20) yields 78, because
3 + 6 +9 + 12 +15 +18 = 63
(15 is already included in the list above!) 5 + 10 = 15 +
sum_3_5 (25) returns 143, because
3 + 6 +9 + 12 + 18 + 21 +24 = 93 (multiples of 5 are lower)
5 + 10 + 15 + 20 = 50 +
sum_3_5 (100) returns in 2318 (without proof)
"" "Return
23
def minquad (number):
" "" find the next smaller or equal integer, a
is square. Examples:
minquad (16) -> 16 (because 4 * 4 = 16 \u0026lt;= 16)
minquad (24) -> 16 (because 4 * 4 = 16 \u0026lt;= 24)
minquad (25) - > 25 (because 5 * 5 = 25 \u0026lt;= 25)
minquad (26) -> 25 (because 5 * 5 = 25 \u0026lt;= 26) return
"" "
number
def triangle (a, w):
"" "draws an equilateral triangle of side a, rotated by
the angle w. w = 0 means that one side is horizional.
w = 90 means that the triangle is rotated to the left by 90 °, ie
one side is vertical.
The triangle will be right next to the selected point
drawn.
"" "pass
dreieck_an_pos def (a, w, x, y):
" "" draw a triangle using the triangle function (a, w) at the
position x, y. "" "pass
def test_ist_schaltjahr ():If
for the year in (1000, 1581, 1582, 1900, 1999, 2003): assert not
ist_schaltjahr (year)
for the year in (1996, 2000, 2004):
ist_schaltjahr assert (year)
print ("ist_schaltjahr ok")
ist_schaltjahr () be implemented properly, would be " ist_schaltjahr ok" output. Otherwise, the program at one of the assert statements are terminated. assert is used as a programmer to examine conditions that indicate if they are not met, a programming error. As a condition of all is the right of the assert, are the True ("everything ok") or False supplies. The test calls for all functions should def main (): You will add together asThis
"" "Hauptprogamm to test all functions" ""
test_ist_dreieck ()
test_ist_quadrat ()
test_ist_schaltjahr (test_fib)
()
test_sum_3_5 ()
test_minquad ()
test_dreieck ()
test_dreieck_an_pos () main
() be also called only (no indentation): main ()If you run the program, it provides output when it works (in spirit ) like this:
ist_dreieck ok ok
ist_quadrat
ist_schaltjahr ok
fib ok
sum_3_5 ok ok
minquad
test_dreieck The functions () and test_dreieck_an_pos () bring a drawing of the following type (depending on views): Here there were the calls: def
test_dreieck ():So it's "visual inspection" is needed.
reset ()
triangular (60, 0)
triangular (60, 90)
triangular (60, -60) def
test_dreieck_an_pos ():
dreieck_an_pos (70, 0, 50, 50)
dreieck_an_pos (70, 180, -50, -50)
0 comments:
Post a Comment