Library 6
All the solutions to the following exercises MUST
- Be written in python, and, apart from doing what
- Contain the following copyright notice:
|
|
where each solver substitutes his own name
for <author>
.
You must each submit one code file, zipped to me at nmla@iba.dk, I will then make a repo with the results.
Exercise OSD.6.0
Write a function isEvenInt(a)
that
returns True
if a
is an even integer,
otherwise ‘False’
Exercise OSD.6.1
Write a function f2c(f)
where f is degrees Fahrenheit. The function must return
a float with the temperature converted to Celsius.
Exercise OSD.6.2
Write a function tri_area(a, b, c)
where
a, b and c are
lengths of a triangle’s sides. The function
returns the area of the triangle. Hint: Use
Heron’s formula.
Exercise OSD.6.3
Write a function avg_list(arr)
where
arr
is a list of numbers. The function must
return the average of the numbers in the list.
Exercise OSD.6.4
Write a function mul_list(arr)
where
arr
is a list of numbers. The function must
return the product of the numbers in the list.
Exercise OSD.6.5
Write a function circ_area(r)
where
r
is the radius of a circle. The function must
return the area of the circle with that radius.
Exercise OSD.6.6
Write a function fizz_buzz(n)
where
n
is an integer. The function must return
fizz
if n
is divisible by 3,
buzz
if n
is divisible by 5, and
fizzbuzz
if n
is divisible by both 3 and 5.
Exercise OSD.6.7
Write a function digit_sum(n)
where
n
is an integer. The function must return
the sum of n
s digits.
Exercise OSD.6.8
Write a function largest_prime_under(n)
where
n
is an integer. The function must return
the largest prime < n
.
Exercise OSD.6.9
Write a function largest_square_under(n)
where
n
is an integer. The function must return
largest square < n
, such that for example
largest_square_under(26) = 25
Exercise OSD.6.10
Write a function is_leap_year(yyyy)
where
yyyy
is an integer interpreted as a calendar year.
The function must return True
is the year
is a leap year, otherwise False
.
Exercise OSD.6.11
Write a function factors(n)
where
n
is an integer. The function must return
a string with the factorization of n
eg
factors(60) = "2^2*3*5"
Exercise OSD.6.12
Write a function letter_freq(s, dic)
where
s
is a string, and dic
is a dictionary of frequencies.
The function must create/update entries in the dictionary.
The dictionary must have an entry for each found
letter from s
and the value of the entry must be
the number of occurrences of that letter.
Exercise OSD.6.13
Write a function fibonacci(n)
where
n
is an integer. The function must return the n
th
fibonacci number.
Exercise OSD.6.14
Write a function roll(n)
where
n
is an integer. The function must return
the outcome of rolling an n
-sided die.
The result must be between 1 and n
.
Exercise OSD.6.15
Write a function validate_password(s)
where
s
is a string. The function must return True
if the password string is in accordance with the
rules, otherwise ‘False’.
A password must be at least 16 characters long,
and consist of only alphanumeric characters
including space. No sequences longer than two
occurrences of the same character are allowed.
Exercise OSD.6.16
Write a function is_anagram(s1, s2) where
s1and
s2are strings. The function must return
Trueif the two string are anagrams of each other, otherwise
false`.