Skip to content

Commit 30f3e0a

Browse files
REmove 3
1 parent 68224a7 commit 30f3e0a

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed

10X/Python/Array/Remove_3.py

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
'''
2+
Remove '3'
3+
You have been given an integer as input. you have to remove all the instances of the digit 3 present in the integer and print the remaining integer.
4+
5+
ex- input= 122345337 output= 122457
6+
7+
To solve this problem you have been given a solution template and you need to complete the following functions.
8+
9+
intToArr-> takes integer as input and returns list of all digits of the number.(ex- 123-> [1,2,3])
10+
11+
arrToInt-> takes list of digits as input and returns the corresponding integer to the list.(ex- [1,2,4] -> 124)
12+
13+
remove_3-> takes a list of integers as input and returns a modified list in which every 3 is removed (ex- [1,2,3,4,3]->[1,2,4])
14+
15+
Input
16+
Input contains only 1 integer as input.
17+
18+
Output
19+
print the final integer in which all 3's are removed.
20+
21+
Example
22+
Input:
23+
24+
12353373999983
25+
26+
Output:
27+
28+
125799998
29+
'''
30+
def intToArr(N):
31+
#complete this function
32+
temp=0
33+
n=0
34+
arr=[]
35+
while N>0:
36+
temp=N%10
37+
N=N//10
38+
arr.append(temp)
39+
return arr
40+
41+
42+
def remove_3(arr):
43+
#complete this function
44+
ar=[]
45+
for i in arr:
46+
if i!=3:
47+
ar.append(i)
48+
return ar[::-1]
49+
50+
def arrToInt(arr):
51+
#complete this function
52+
sumo=0
53+
for i in arr:
54+
if i==0:
55+
sumo*=10
56+
elif i==3:
57+
pass
58+
else:
59+
sumo=sumo*10+i
60+
61+
return sumo
62+
63+
64+
#DO NOT change anything below this line
65+
66+
N=int(input())
67+
arrNum=intToArr(N)
68+
arrNumWithout3=remove_3(arrNum)
69+
70+
print(arrToInt(arrNumWithout3))

0 commit comments

Comments
 (0)