Write a function, performance_level(avg: float), that takes the average score and returns a number representing performance:
- return 3 if avg is above 80
- return 2 if avg is between 50 and 80 (including both)
- return 1 otherwise
Define a function, triangle_type, that takes three sides, a, b and c and:
- It returns "equilateral" if all sides are equal.
- It returns "isosceles" if two sides are equal.
- It returns "scalene" otherwise.
Write a function, dash_separated, which takes a string, s, and returns the characters
of the string separated by dashes (-).
Example:
>>> dash_separated("abc")
"a-b-c-"
>>> dash_separated("12")
"1-2-"
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
(<, >, !=, ...).
You're working on a role-playing game where each player chooses a character and a weapon.
Based on those choices, the player's power level is calculated.
Each character and weapon contributes a certain number of points:
Characters:
- warrior -> +30 power
- mage -> +25 power
- archer -> +20 power
- any other class -> +10 power
Weapons:
- sword -> +15 power
- bow -> +10 power
- any other weapon -> +5 power
Set the character and weapon variables to any values you like, and power to 0.
Write a program that updates power for all possible values of character and weapon.
For example, if character is mage and weapon is bow, power should be 35.
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?
def divide(n):
while True:
break
n = n / 2
print('done')
print('DONE')
return n
res = divide(4)
Given the above script:
| What is the value of res: | ||
| What is the printed value: |
def add(n):
total = 10
for num in range(n):
total = total + 2
return total
Given the above script, what are the results of the following expressions:
| add(1): | ||
| add(2): | ||
| add(5): |
Complete execution flow of the following program
def calculate(): sub() sub() def sub(): a = 50 b = a - 40 print(b) calculate()
10 10 >>>
Complete execution flow of the following program
def add(a, b): print(a + b ** b) def sub(x, y): print(x - y) add(x + x, x + y) sub(1, 2)
-1 29 >>>