Define a function, fruit_color, that takes one string, fruit,
and:
- It returns "red" if fruit is "apple".
- It returns "yellow" if fruit is "banana".
- It returns "orange" if fruit is "orange".
- It returns "unknown" otherwise.
Write a function that takes three numbers, a, b and c and:
- It returns "both" if a is divisible by b and c
- It returns "first" if a is divisible by b but not c
- It returns "second" if a is divisible by c but not b
- It returns "neither" otherwise
Example:
>>> check_divisibility(6, 2, 3)
both
>>> check_divisibility(6, 2, 5)
first
>>> check_divisibility(8, 3, 4)
second
>>> check_divisibility(7, 2, 3)
neither
Write a function that takes one positive integer as argument, n and returns sum of all numbers between. 0 and n (including n).
Write a function is_even, that takes a number and returns True if it is even, or False otherwise.
Write a function even_or_odd_message, that takes a number and returns "Even" if it is even,
or "Odd" if it is odd.
Restriction: You CANNOT modulus (%) inside this function's body.
Suppose the cover price of a book is $24.95, but bookstores get a 40% discount. Shipping costs $3 for the first copy and 75 cents for each additional copy. What is the total whole sale cost for 60 copies?
Write a function that takes a string and returns number of characters.
Example:
>>> count('a')
1
>>> count('11')
2
>>> count('pse')
3
Restriction: You CANNOT use len.
def calculate(member, total):
if member and (total > 100):
return total - total * 0.2
elif member:
return total - total * 0.05
elif total > 100:
return total - total * 0.1
return total
Given the above script, what are the results of the following calls:
| calculate(False, 90): | ||
| calculate(True, 100): | ||
| calculate(False, 200): |
def dosmth(num, string):
for s in string:
num = num + 1
return num
def dosmth2(string):
v = 2
for char in string:
v = v * 2
return v
Given the above script, what are the results of the following expressions:
| dosmth(1, '12345'): | ||
| dosmth2('123'): | ||
| dosmth(0, 'ani') + dosmth2('a'): |
Complete execution flow of the following program
def countup(n): while n < 0: print(n) n = n + 1 print('Blastoff!') res = countup(-3) print(res)
Complete execution flow of the following program
def calculate(a, b): p = prod(a, b) d = diff(a, b) res = p + d return res def prod(x, y): res = x * y return res def diff(x, y): d = x - y return d c = calculate(5, 3)