-
Notifications
You must be signed in to change notification settings - Fork 17
/
online03.py
159 lines (120 loc) · 2 KB
/
online03.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
# -*- coding: utf-8 -*-
"""Online03.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1XKGWZ2GthgBOMfjEmsOv5BpUHs7aZKXx
"""
#1 - ali va hasan be madrese raftan.
v = input("jomle ra vared kon : ")
vlist = v.split(' ')
print(len(vlist))
vlist
#2 - aabbcdddefgha
string = input("reshte ra vared kon : ")
d = dict()
for c in string:
if d.get(c,False):
continue
else:
d[c]=string.count(c)
for k,v in d.items():
print(k," ======> ", v)
print(d)
#3-1
def max3(a, b, c):
if a>b and a>c:
return a
elif b>a and b>c:
return b
else:
return c
max3(1,2,3)
max3(2,52,25)
x,y,z = 1,2,-10
max3(x,y,z)
#3-2
def kamel(a):
maghsom = []
sum = 0
for i in range(1,(a//2)+1):
if a%i == 0 :
maghsom.append(i)
sum = sum + i
if sum == a :
return True
else:
return False
kamel(10)
kamel(6)
#3-2prim
def kamel_maghsom(a):
maghsom = []
sum = 0
for i in range(1,(a//2)+1):
if a%i == 0 :
maghsom.append(i)
sum = sum + i
maghsom.append(a)
if sum == a :
return True,maghsom
else:
return False,maghsom
kamel_maghsom(6)
xT, mT = kamel_maghsom(23)
xT
mT
#3-3
def aval(x):
counter = 0
for i in range(2,(x//2)+1):
if x%i == 0:
counter = counter + 1 #counter +=1
if counter != 0:
return False
return True
aval(10)
aval(23)
aval(2)
#3-4
def fact(x):
f = 1
for i in range(2,x+1):
f *= i
return f
fact(5)
def fact2(x):
f = 1
while(x!=1):
f *=x
x -=1
return f
fact2(5)
#3-5
def bmm(x,y):
while(y != 0):
z = x//y
x, y = y, x-(y*z)
return x
bmm(125,35)
#3-6
def kmm(x,y):
return (x*y)//bmm(x,y)
kmm(125,35)
def argham(number):
counter = 0
while(number != 0):
counter +=1
number = number // 10
return counter
argham(12500)
argham(123456789)
#3-7
def sum_a(number):
sum = 0
while(number != 0):
sum += number%10
number = number // 10
return sum
sum_a(123)
sum_a(10000000000000000)
sum_a(1258)