-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfunc_programs.py
More file actions
146 lines (70 loc) · 2.24 KB
/
func_programs.py
File metadata and controls
146 lines (70 loc) · 2.24 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# to return a list of even numbers
def evens(start, end):
l = []
for i in range(start, end+1):
if i % 2 == 0:
l.append(i)
return l
# print(evens(1, 10))
# print(evens(11, 30))
####################################################################
# to return a dictionary with element and its count in any sequence
def count_element(sequence):
d = {}
for item in sequence:
if item not in d:
d[item] = 1
else:
d[item] += 1
return d
# print(count_element("hello"))
# print(count_element([1, 2, 3, 4, 5, 6, ]))
# to return a list of first "n" prime numbers
def first_n_prime(n):
l = []
count = 0
num = 0
while count < n:
if num > 1:
for i in range(2, num):
if num % i == 0:
break
else:
count += 1
l.append(num)
num += 1
return l
# print(first_n_prime(5))
# print(first_n_prime(10))
#################################################################
# to check if the given number is prime or not
def is_prime(number):
for i in range(2, number):
if number % i == 0:
print("Number is not prime")
break
else:
print("Number is prime")
# is_prime(8)
#####################################################################
# function to return last digit of the given number
def last_digit(num):
return int(str(num)[-1]) # return num % 10
res = last_digit(1234)
# print(res)
######################################################################
# return last n elements from the sequence as the list
def tail(sequence, n):
return list(sequence[-n:])
# print(tail("hello", 3))
########################################################################
# return a list of words starting with vowels
string = "It is very sunny today"
def vowels_list(iterable):
l = []
for i in iterable:
if i[0].lower() in "aeiou":
l.append(i)
return l
list_ = string.split()
print(vowels_list(list_))