-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathques.py
More file actions
36 lines (29 loc) · 828 Bytes
/
ques.py
File metadata and controls
36 lines (29 loc) · 828 Bytes
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
def listsum(ls):
if len(ls) == 1:
return ls[0]
else:
return ls[0] + listsum(ls[1:])
print(listsum([1,2,3,4,5]))
def tostr(num,base):
strconv = "0123456789ABCDEF"
if num < base:
return strconv[num]
else:
return tostr(num//base,base) + strconv[num%base]
print(tostr(999999,16))
def rev(instr):
if len(instr) == 1:
return instr[-1]
else:
return instr[-1] + rev(instr[:-1])
print(rev("hello"))
def ispal(instr):
instr = instr.replace(" ","").replace(",","").replace("-","").lower()
isPal = True
if instr[0] != instr[-1]:
return False
if len(instr) == 1 or 0:
return isPal
else:
return ispal(instr[1:-1])
print(ispal("Reviled did I live, said I, as evil I did deliver"))