-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoddnum_extracted_from_string.py
More file actions
63 lines (42 loc) · 1.07 KB
/
oddnum_extracted_from_string.py
File metadata and controls
63 lines (42 loc) · 1.07 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
a = input("enter the string: ")
print(a)
num = []
for i in a :
if i.isnumeric() :
num.append(i)
final = ['-1']
check = False
for i in num :
count = 1
for j in final :
check = False
if int(i) != int(j) and count == len(final):
check = True
if i == j :
break
count += 1
if check == True :
final.append(i)
final.pop(0)
final.sort()
even = True
for i in final :
if int(i) % 2 != 0 :
even = False
break
if even == True :
print(-1)
if int(final[0]) == 0 :
temp = final[0]
final[0] = final[1]
final[1] = temp
if even == False:
if int(final[-1]) % 2 == 0 :
for i in range(-1,-len(final),-1):
if int(final[i]) % 2 != 0 :
val = final[i]
final.pop(i)
final.append(val)
for j in final :
print(j,end="")
break