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 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
ⓘ
def first(): print(3) def second(): first() first() def third(): second() second() first() second() third()
After the execution of the above script:
Which value is printed: | |
How many times is the value printed: |
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_loyal_customer, that takes an integer, years, and returns True if it is greater than or equal to 3, or False otherwise.
Write a function has_coupon, that takes a string, code, and returns True if code is "DISCOUNT20", and False otherwise.
Write a function discount, that takes an integer and a string, years and code,
and:
- It returns 0.1 if years is greater than or equal to 3 and code is not "DISCOUNT20"
- It returns 0.15 if code is "DISCOUNT20" and years is less than 3.
- It returns 0.2 if years is greater than or equal to 3 and code is "DISCOUNT20"
- It returns 0.0 if years is less than 3 and code is not "DISCOUNT20"
Restriction: You CANNOT use any relational operator inside this function's body
(<, >, !=, ...).
ⓘ
Write a function that takes two numbers, x nad y, and:
- It prints 'x and y are positive integers' if x and y are both positive integers.
- It prints 'x and y are negative integers' if x and y are both negative integers.
- It prints 'x and y are zero' if x and y are both 0.
- It prints 'x and y have different signs' otherwise.
ⓘ
def clothing_recommendation(temperature, is_raining): if temperature < -50 or temperature > 60: return "Invalid" elif temperature >= 25: if is_raining == "yes": return "Light clothes and umbrella" else: return "Light clothes" elif 15 <= temperature <= 24: return "Jacket" else: return "Coat"
Given the above script, what are the results of the following calls:
clothing_recommendation(25, "no"): | |
clothing_recommendation(25, "yes"): | |
clothing_recommendation(24, "yes"): |
def add(n, m): total = 0 while True: if total == 100: break total = total + n + m return total res = add(20, 30)
Given the above script:
What is the value of res: |
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 >>>
Complete execution flow of the following program
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 d = dosmth2('ab') - dosmth(3, 'ab')