-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPython ass 21.txt
88 lines (71 loc) · 2.52 KB
/
Python ass 21.txt
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
lst = [5, 6, 7, 8, 9]
def next_in_line(lst,num):
if len(lst) > 0 :
lst.append(num)
return lst[1:]
else:
print("'No list has been selected'")
***************************************************
next_in_line([5, 6, 7, 8, 9], 1)
**********************************************
next_in_line([1, 10, 20, 42 ], 6)
********************************************
next_in_line([], 6)
******************************
def get_budgets(listDict):
sum = 0
for dc in listDict:
for k,v in dc.items():
if k == 'budget':
sum = sum + v
return sum
****************************************
get_budgets([
{ 'name': 'John', 'age': 21, 'budget': 23000 },
{ 'name': 'Steve', 'age': 32, 'budget': 40000 },
{ 'name': 'Martin', 'age': 16, 'budget': 2700 }
])
***************************************************
get_budgets([
{ 'name': 'John', 'age': 21, 'budget': 29000 },
{ 'name': 'Steve', 'age': 32, 'budget': 32000 },
{ 'name': 'Martin', 'age': 16, 'budget': 1600 }
])
**************************************************
def alphabet_soup(str):
return ''.join(sorted(str))
*************************************
alphabet_soup('hello')
*****************************
alphabet_soup('edabit')
***************************
alphabet_soup('hacker')
****************************
alphabet_soup('geek')
**************************
alphabet_soup('javascript')
********************************
def compound_interest(amt, years, intrest, compPeriod):
future_value = amt *(1 + (intrest/compPeriod)) ** (years * compPeriod)
return round(future_value,2)
******************************************
compound_interest(100, 1, 0.05, 1)
************************************
compound_interest(3500, 15, 0.1, 4)
***********************************
compound_interest(100000, 20, 0.15, 365)
*************************************************
def return_only_integer(lst):
int_list = []
for i in lst:
if type(i) == int:
int_list.append(i)
return int_list
*******************************************
return_only_integer([9, 2, 'space', 'car', 'lion', 16])
*******************************************************
return_only_integer(['hello', 81, 'basketball', 123, 'fox'])
****************************************************************
return_only_integer([10, '121', 56, 20, 'car', 3, 'lion'])
*******************************************************************
return_only_integer(['String', True, 3.3, 1])