-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathex.py
164 lines (114 loc) · 2.93 KB
/
ex.py
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
def prime(num):
prime1=[]
for i in range(2,num):
if num%i==0:
#print("not a prime")
break
else:
prime1.append(num)
print(prime1)
prime(50)
#print(num)
#for i in range(2,50):
# prime(i)
###############
def prime_factors(num):
factors=[]
divisor=2
while(divisor<=num):
if num%divisor==0:
factors.append(divisor)
num=num/divisor
else:
divisor+=1
return factors
print(prime_factors(120))
##########3 madam malayalam suus
def palin(s):
s1=''
s=s.lower()
garbage=['-',"'"]
print(s)
l=len(s)+1
for i in s[-1:-l:-1]:
s1+=i
print(s1)
if s==s1:
print("yes")
else:
print("no")
palin("gohan gasal amimalasa'-gnahog")
##########################
import string
def palin_sent(s):
s=s.lower()
chars=string.ascii_lowercase
s=''.join(i for i in s if i in chars)
if s==s[::-1]:
return True
return False
print(palin_sent("gohan gasal amimalasa'-gnahog"))
###########
# bana
def sort_sen(s):
s=s.split()
s.sort(key=str.casefold)
print(s)
(sort_sen("JACK apple BANANA ORANGE"))
###########
#sorting mtd 2:
def sort_ss(s):
s=s.split()
print(s)
s=[word.lower()+word for word in s]
s=sorted(s)
s=[word[(len(word)//2):] for word in s]
print(s)
(sort_ss("JACK apple BANANA ORANGE"))
#############
def index_all(lst,num):
indices=[]
for i in range(len(lst)):
if num==lst[i]:
indices.append([i])
elif isinstance(lst[i],list):
for index in index_all(lst[i],num):
#indices.append([i])
indices.append([i]+index)
return indices
lst=[ [[1,2,3],2,[1,3]],[1,2,3] ,2 ]
print(index_all(lst,2))
####3
import time,random
def waiting_game():
target=random.randint(2,4)
print(f'your target time is {target} seconds')
input("--Press enter to begin--")
start=time.perf_counter()
print(start)
input(f"press enter after {target} seconds")
print(time.perf_counter())
elapsed=time.perf_counter()-start
print("elasped time is {} seconds".format(elapsed))
if elapsed==target:
print("perfect")
elif target>elapsed:
print("{0:.3f} secs too fast ".format(target-elapsed))
else:
print("{0:.3f} secs too slow ".format(elapsed-target))
#waiting_game()
#################
#def save_dic_to_file(d,path):
# with open(path,"w") as f:
# f.write(d)
#d="hey"
#save_dic_to_file(d,'sm1.txt')
colours = [["#660000","#863030","#ba4a4a","#de7e7e","#ffaaaa"],["#a34b00","#d46200","#ff7a04","#ff9b42","#fec28d"],["#dfd248","#fff224","#eefd5d","#f5ff92","#f9ffbf"],["#006600","#308630","#4aba4a","#7ede7e","#aaffaa"]]
target="#660000"
for i, c in enumerate(colours):
#print(i,c)
if target in c:
print((i,c.index(target)))
#######
d={'1':'e','c':'i'}
print(d['1'])