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
Create a function, random_number, that returns a random integer between 10 and 30 (inclusive).
Write a function that takes a string as argument and using a for loop it prints all its letters, one per line.
def calculate(x, y, z):
print(x + y - z)
def call_function(a, b):
calculate(a, b, a)
print(a - b)
call_function(3 - 1, 2 + 2)
What is printed after we execute the above script? Write the values in the order that they are printed.
Define a function named print_smth, which prints Shnete e pranvere!.
Call print_smth.
Define a function named repeat_smth, which calls print_smth once.
Call repeat_smth.
Write a function, add, that takes two numbers and returns their sum.
Write a function, sub, that takes two numbers and returns their difference (first argument minus second).
Write a function, that takes two numbers, n and m, and returns (n - m) + m.
Restrictions:
- You cannot use - or + inside htis function's body
- You should use sub to subtract m from n, and add to add the result of n - m and m.
def power(n):
total = 0
while True:
total = total + n
print('pse')
break
return total
print('ani')
res = power(10)
Given the above script:
| What is the value of res: | ||
| What is the printed value: |
def do_smth_twice(a, b):
do_smth(a, a)
do_smth(a, b)
def do_smth(a, b):
print(a + b)
do_smth('ani', 'pse')
What is printed if we execute the above program?
Complete execution flow of the following program
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)
5 5 5 5 >>>
Complete execution flow of the following program
def calculate(x): return add(x, x, x ** 2) def add(a, b, c): return a + b + c res = calculate(2) print(res)
8 >>>