Define a function, finish, that prints "finish".
Define a function, proceed, that calls finish once.
Define a function, start, that calls proceed once.
Call start.
Write a function, countup, that takes one positive integer, n,
and prints numbers from 1 up to and including n, one per line.
End with printing "Done!".
Example:
>>> countup(3)
1
2
3
Done!
Restriction: You cannot use for or if.
Define a function, temp_feel, that takes one number, temp,
and:
- It returns "cold" if temp is lower or equal to 10.
- It returns "cool" if temp is between 10 and 20 (including 20).
- It returns "warm" if temp is between 20 and 30 (including 30).
- It returns "hot" if temp is greater than 30.
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.
Define a function named shtyp_tekstin, which prints Shndet prej mejet te m'i falesh.
Call shtyp_tekstin.
Define a function named perserit_tekstin, which calls shtyp_tekstin three times.
Call perserit_tekstin.
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 sub(m, n):
for i in range(n):
m = m - 3
return m
| sub(10, 1): | ||
| sub(20, 2): | ||
| sub(9, 3): |
def add(n):
total = 10
for num in range(n):
total = total + 2
return total
| add(1): | ||
| add(2): | ||
| add(5): |
Complete execution flow of the following program
def sum(n): total = 0 for i in range(n): total = total + i return total print(sum(3))
Complete execution flow of the following program
def print_sum_and_diff(x, y): print(x + y) print(x - y) print(print_sum_and_diff(5, 2))