-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.py
More file actions
121 lines (88 loc) · 3.96 KB
/
functions.py
File metadata and controls
121 lines (88 loc) · 3.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# coding: utf-8
def interest(A, n, p):
"""
Let _p_ be a bank’s interest rate in percent per year. An initial amount _A_ has then grown to
n
A = A ( 1 + p / 100 )
after _n_ years. Make a function `interest` taking arguments _A_, _p_, and _n_, for computing
the amount of money after several years and use it to compute how much money 1000 euros have
grown to after three years with 5% interest rate.
"""
# Write your code here
def celsius(farenheit):
"""
The formula for converting Fahrenheit degrees to Celsius reads
C = 5/9 (F − 32).
Write a function ``celsius(farenheit)`` that implements this formula.
"""
# Write your code here
def convert_to_usd(pln):
"""
Write a function `convert_to_usd`, which takes parameter `pln`, for an amount in PLN.
The function should return the amount in USD. Assume 3.85 PLN = 1 USD.
"""
# Write your code here
def calc_net(gross, vat=23):
"""
Write a fucntion `calc_net`, which takes arguments:
* `gross` for gross price,
* `vat`, for VAT percentage (a number in a range 0–100). Default value for VAT should be 23%.
The function should return the net price. Think about the calculations you need to do.
"""
# Write your code here
def get_short_words(text, n=5):
"""
Write a function `get_short_words`, which takes a text and returns the list of words shorter
than _n_ characters. _n_ is a function argument with a default value of 5.
"""
# Write your code here
def initials(name):
"""
Write a functions `initials`, which takes a person's full name as an argument and converts all
the names but the last one into initials. Only the names beginning with capital letter should
be shortened.
"""
def message(data):
"""
Write a function `message`, which takes as an argument a dictionary with the keys:
* **name**,
* **role**,
* **movie**.
The function should return a formatted string "In _movie_, _name_ is a _role_.", where
_movie_, _name_, and _role_ is replaced with the corresponding values from the dictionary.
If any of the values is missing from the dictionary, the function should return `None`.
"""
# Write your code here
def quadratic_equation(a, b, c):
"""
Write a function `quadratic_equation(a, b, c)` that finds all **real** solutions of the quadratic equation of the form
a x² + b x + c = 0
The function should return a tuple containing zero, one, or two solutions. The tuple must be empty if either
no solution exists or there is an infinite number of solutions.
You must correctly handle a case of _a_ equal to 0.
"""
# Write your code here
def dice(num):
"""
Write a function `dice(num)`, which simulates a roll with a 6-side dice. `num` is a number
of dice to throw. The function should return the sum of the dice.
"""
# Write your code here
def histogram(throws=500):
"""
Using the function `dice(num)` from the previous exercise, write a function `print_histogram(throws)` that
rolls two dice _throws_ times and **prints** a histogram of the resulting numbers according to the example below:
2: ##############
3: #########################
4: ##############################################
5: #####################################################################
6: ##################################################################
7: ###########################################################################################
8: ####################################################################
9: ###################################################
10: ###################################
11: ##################
12: #################
Please mind the formatting (e.g. every number **must** span two characters and be right-aligned)!
"""
# Write your code here