Define a function, prod, which takes two numbers, a and b, and returns their product.
Define a function, multiply_up_to, which takes one positive integer, n,
and returns product of all numbers between 1 and n (not including n). Example:
>>> multiply_up_to(4)
6
>>> multiply_up_to(5)
24
>>>
Restrictions:
- You cannot use range
- You cannot use *
Write a function that takes a driver's speed speed and a boolean is_birthday.
Return:
- 0 for no ticket if speed <= 60 (or 65 on birthday)
- 1 for small ticket if speed <= 80 (or 85 on birthday)
- 2 for big ticket otherwise
Example:
>>> ticket(64, True)
0
>>> ticket(64, False)
1
Write a function, shout_down, that takes a positive integer, n,
and prints all numbers between n and 1 (inclusive), each in a new line.
Print "BOOM!" after the loop.
Example:
>>> shout_down(3)
3
2
1
BOOM!
Restriction: You cannot use for or if.
Write a function that takes two numbers, a and b, and:
- It prints 'a is lower than b' if a is lower than b.
- It prints 'a is greater than b' if a is greater than b.
- It prints 'a is equal to b' otherwise.
Write a function that takes one string as argument and inside a for loop print every
vowel that appears in the string, each in a new line. (vowels in english are a, e, i, o, u).
Example:
>>> print_vowels('something')
o
e
i
Write a function, adjust_cooling(status: str), that determines the appropriate cooling power
based on the current temperature status:
- "too cold" -> 0.2
- "optimal" -> 0.5
- "too warm" -> 1.0
Example:
>>> adjust_cooling("too warm")
1.0
>>> adjust_cooling("optimal")
0.5
>>> adjust_cooling("too cold")
0.2
def print_name(name):
print(name)
print(name)
def print_number(d):
res = d + d
res
def print_surname(surname):
print_name(surname)
print_name(surname)
print_number(3)
print_surname(5)
In the above script:
| What is the printed value: | ||
| How many times is that value printed: |
def calculate(a, b):
if a == 'first' and b < 0:
return b + b
elif a != 'first' and b > 0:
return b * 2
return b
Given the above script, what are the results of the following calls:
| calculate('second', 1): | ||
| calculate('second', -1): | ||
| calculate('first', 1): |
Complete execution flow of the following program
def call_add(): add() def add(): s = 4 * 5 print(s) call_add() add()
Complete execution flow of the following program
import math def distance(x1, y1, x2, y2): dx = x2 - x1 dy = y2 - y1 dsquared = dx**2 + dy**2 result = math.sqrt(dsquared) return result d = distance(1, 2, 4, 6) print(d)