Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 3c9d62a

Browse files
Done with 60 python practice questions.
1 parent b959281 commit 3c9d62a

8 files changed

+162
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
def removeDuplicate(lst):
2+
noDuplicateList = []
3+
for i in lst:
4+
if i not in noDuplicateList:
5+
noDuplicateList.append(i)
6+
return noDuplicateList
7+
8+
emptyList = []
9+
sizeOfList = int(input('Enter size of the list: '))
10+
for i in range(sizeOfList):
11+
value = int(input('Enter values to store in a list: '))
12+
emptyList.append(value)
13+
print(emptyList)
14+
lst = removeDuplicate(emptyList)
15+
print('List after removing duplicate elements is',lst)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
def countEvenOddNos(lst):
2+
countEvenNos = 0
3+
countOddNos = 0
4+
for i in lst:
5+
if (i % 2) == 0:
6+
countEvenNos += 1
7+
else:
8+
countOddNos += 1
9+
print('The total even no\'s in a list are', countEvenNos, 'and the total odd no\'s are', countOddNos)
10+
11+
12+
emptyList = []
13+
sizeOfList = int(input('Enter size of the list: '))
14+
for i in range(sizeOfList):
15+
value = int(input('Enter values to store in a list: '))
16+
emptyList.append(value)
17+
print(emptyList)
18+
countEvenOddNos(emptyList)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
lst = []
2+
sizeOfList = int(input('Enter size of the list: '))
3+
for i in range(sizeOfList):
4+
values = int(input('Enter values to store in a list: '))
5+
lst.append(values)
6+
print('List is', lst)
7+
8+
# 1st logic.
9+
10+
# sum = 0
11+
# for i in lst:
12+
# sum += i
13+
# print('Sum of elements of the list is', sum)
14+
15+
16+
# 2nd logic.
17+
18+
sum = 0
19+
for i in range(sizeOfList):
20+
sum += lst[i]
21+
# print('Sum of elements of the list is', sum)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
lst = []
2+
sizeOfList = int(input('Enter size of the list: '))
3+
for i in range(sizeOfList):
4+
values = int(input('Enter values to store in a list: '))
5+
lst.append(values)
6+
print('List is', lst)
7+
8+
countValue = int(input('Enter no to find its frequency in a list: '))
9+
count = 0
10+
for i in lst:
11+
if i == countValue:
12+
count += 1
13+
print(f'Frequency of {countValue} in the list is {count}')
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
lst = []
2+
sizeOfList = int(input('Enter size of the list: '))
3+
for i in range(sizeOfList):
4+
values = int(input('Enter values to store in a list: '))
5+
lst.append(values)
6+
print('List is', lst)
7+
8+
# To find maximum number from a list.
9+
# # First logic.
10+
# max = lst[0]
11+
# for i in lst:
12+
# if i > max:
13+
# max = lst[i]
14+
# print('Maximum number in a list is', max)
15+
16+
# Second Logic:
17+
18+
# max = lst[0]
19+
# for i in range(sizeOfList):
20+
# if lst[i] > max:
21+
# max = lst[i]
22+
# print('Maximum number in a list is', max)
23+
24+
25+
# To find minimum number from a list.
26+
min = lst[0]
27+
for i in lst:
28+
if (min > i):
29+
min = lst[i]
30+
print('Minimum number in the list is', min)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# In this program we write a logic that reverse a list itself.
2+
'''
3+
List stores different types of elements in it.
4+
Array stores similar types of elements in it.
5+
In this program we stores int into a list that's why it becomes array.
6+
'''
7+
8+
lst = []
9+
sizeOfList = int(input('Enter size of the list: '))
10+
for i in range(sizeOfList):
11+
values = int(input('Enter values to store in a list: '))
12+
lst.append(values)
13+
print('Original list is =', lst)
14+
15+
i = 0
16+
j = sizeOfList - 1
17+
while(i < j):
18+
temp = lst[i]
19+
lst[i] = lst[j]
20+
lst[j] = temp
21+
i += 1
22+
j -= 1
23+
print('List aftre reverse =', lst)
24+
25+
# for i in range(sizeOfList):
26+
# print(lst[i])
27+
28+
# for i in lst:
29+
# print(i)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
lst = []
2+
sizeOfList = int(input('Enter size of the list: '))
3+
for i in range(sizeOfList):
4+
values = int(input('Enter values to store in a list: '))
5+
lst.append(values)
6+
print('List is', lst)
7+
maxValue = max(lst)
8+
minValue = min(lst)
9+
print('Maximum number of the list is', maxValue)
10+
print('Minimum number of the list is', minValue)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
lst = []
2+
sizeOfList = int(input('Enter size of the list: '))
3+
for i in range(sizeOfList):
4+
values = int(input('Enter values to store in a list: '))
5+
lst.append(values)
6+
print('List is', lst)
7+
8+
# 1st method.
9+
# minValue = min(lst)
10+
# maxValue = max(lst)
11+
# print('Minimum number in the list is', minValue, 'and maximum number in the list is', maxValue)
12+
# lst.remove(minValue)
13+
# lst.remove(maxValue)
14+
# secondMinvalue = min(lst)
15+
# secondMaxvalue = max(lst)
16+
# print('Second minimum number in the list is', secondMinvalue, 'and second maximum number in the '
17+
# 'list is', secondMaxvalue)
18+
19+
20+
# Find minimum/maximum and second minimum/maximum number in the list.
21+
lst.sort()
22+
print('Minimum Number =', lst[0], 'and maximum number is =', lst[-1])
23+
print('Second Minimum Number =', lst[1], 'and second maximum number in the list is =', lst[-2])
24+
25+
# for max you can also write sizeOfList - 1
26+
# for second max value you can also write sizeOfList - 2

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /