-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem22to30.py
More file actions
120 lines (75 loc) · 2.55 KB
/
Problem22to30.py
File metadata and controls
120 lines (75 loc) · 2.55 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
# problem 22
def countFours(x):
counter = 0
for i in x:
if i == 4:
counter = counter + 1
return counter
print("4 is repeated " + str(countFours([1, 2, 3, 4, 5, 4, 7])) + " times")
print("--------------Problem 22 End--------------------------")
# problem 23
def substringCopy(sampleString, sampleNumber):
length = len(sampleString)
subStr = sampleString
if length > sampleNumber:
subStr = sampleString[: sampleNumber]
return subStr * sampleNumber
sampleString = raw_input("Enter Some String: ")
sampleNumber = int(raw_input("Enter Some Number: "))
print(substringCopy(sampleString, sampleNumber))
print("--------------Problem 23 End--------------------------")
# problem 24
def isVowel(char):
vowels = ('a', 'e', 'i', 'o', 'u')
return vowels.__contains__(char)
print(isVowel('c'))
print(isVowel('a'))
print("--------------Problem 24 End--------------------------")
# problem 25
def is_group_member(list, x):
return list.__contains__(x)
print(is_group_member([1, 5, 8, 3], 3))
print(is_group_member([5, 8, 3], -1))
print("--------------Problem 25 End--------------------------")
# problem 26
def histogram(list):
for i in list:
temp = ''
for j in range(0, i):
temp += "@ "
print(temp)
histogram([2, 3, 6, 5])
print("--------------Problem 26 End--------------------------")
# problem 27
def concatinate(list):
temp = ''
for i in list:
temp += str(i)
return temp
print(concatinate([1, 5, 12, 2]))
print("--------------Problem 27 End--------------------------")
# problem 28
numbers = [
386, 462, 47, 418, 907, 344, 236, 375, 823, 566, 597, 978, 328, 615, 953, 345,
399, 162, 758, 219, 918, 237, 412, 566, 826, 248, 866, 950, 626, 949, 687, 217,
815, 67, 104, 58, 512, 24, 892, 894, 767, 553, 81, 379, 843, 831, 445, 742, 717,
958, 743, 527
]
for i in numbers:
if i == 237:
print(237)
break
else:
if i % 2 == 0:
print(i)
print("--------------Problem 28 End--------------------------")
# problem 29
color_list_1 = {"White", "Black", "Red"}
color_list_2 = {"Red", "Green"}
print(color_list_1.difference(color_list_2))
print("--------------Problem 29 End--------------------------")
# problem 30
base = int(raw_input("Enter base of the triangle: "))
height = int(raw_input("Enter height of the triangle: "))
print("Area of Triangle with Base " + str(base) + " and height " + str(height) + " is " + str(0.5 * base * height))
print("--------------Problem 30 End--------------------------")