Skip to content

Commit 973ebf9

Browse files
authored
Add files via upload
1 parent 233b37c commit 973ebf9

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

main.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
def intreverse(n):
2+
rev=0
3+
while(n!=0):
4+
r=n%10
5+
n=n//10
6+
rev=rev*10+r
7+
return (rev)
8+
9+
def matched(s):
10+
open_list = ["("]
11+
close_list = [")"]
12+
stack = []
13+
for i in s:
14+
if i in open_list:
15+
stack.append(i)
16+
if i in close_list:
17+
pos = close_list.index(i)
18+
if ((len(stack) > 0) and
19+
(open_list[pos] == stack[len(stack)-1])):
20+
stack.pop()
21+
else:
22+
return (False)
23+
if len(stack) == 0:
24+
return (True)
25+
else:
26+
return (False)
27+
28+
def sumprimes(l):
29+
sum=0
30+
for num in l:
31+
if num>1:
32+
for i in range(2,num):
33+
if(num%i)==0:
34+
break
35+
else:
36+
sum+=num
37+
return (sum)
38+
import ast
39+
40+
def tolist(inp):
41+
inp = "["+inp+"]"
42+
inp = ast.literal_eval(inp)
43+
return (inp[0],inp[1])
44+
45+
def parse(inp):
46+
inp = ast.literal_eval(inp)
47+
return (inp)
48+
49+
fncall = input()
50+
lparen = fncall.find("(")
51+
rparen = fncall.rfind(")")
52+
fname = fncall[:lparen]
53+
farg = fncall[lparen+1:rparen]
54+
55+
if fname == "intreverse":
56+
arg = parse(farg)
57+
print(intreverse(arg))
58+
elif fname == "matched":
59+
arg = parse(farg)
60+
print(matched(arg))
61+
elif fname == "sumprimes":
62+
arg = parse(farg)
63+
print(sumprimes(arg))
64+
else:
65+
print("Function", fname, "unknown")
66+

0 commit comments

Comments
 (0)