-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmy_samples.py
More file actions
201 lines (145 loc) · 3.39 KB
/
my_samples.py
File metadata and controls
201 lines (145 loc) · 3.39 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
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
items=["La", "One", "Two",1,2,3,5,"new","Igorku"]
def list_parser(list):
str_list=[]
num_list=[]
for i in list:
if isinstance (i, (float, int)):
num_list.append(i)
elif isinstance (i, str):
str_list.append(i)
else:
pass
return str_list, num_list
print (list_parser(items))
items2=['ala','m3m',3,67,78,8]
print(list_parser(items2))
def my_sum(my_list):
total=0
for i in my_list:
if isinstance (i, (int,float)):
total=total+i
return total
print(my_sum(items2))
def my_avg(my_list):
the_sum=my_sum(my_list)
num_of_items=len(my_list)
return the_sum/(num_of_items*1.0)
my_avg(items2)
def count_sum_avg(my_list):
total=0
count=0
for i in my_list:
if isinstance(i, (float,int)):
count=count+1
total=total+i
return count,total, total/count
count_sum_avg(items2)
text="this is {a} formatted string".format(a="new")
print(text)
def count(a,b):
return a*b
def plus (a,b):
return a+b
def minus(a,b):
return a-b
def divide(a,b):
return a*1.0/b
count(6,10)
plus(6,10)
minus(6,10)
divide(6,10)
text_2="new {0}".format("blabla")
print(text_2)
print("lala %.3f") %(2.12312313)
import datetime
today=datetime.date.today()
text='{today.month}/{today.day}/{today.year}'.format(today=today)
print(text)
now=datetime.datetime.utcnow()
text_3=now.strftime('%Y-%m-%d %H:%M:%S.%f')
default_name=["Igor","Ivan","Stepan","Olga","Roman","Yuriy"]
default_amounts=[122.50, 23.99, 124.32, 323.4,20.22, 99.99]
unf_message="""Hi there {name}!!!
Thanks for a great work.
{date} was a good day
Your purchuase total is {total}
Support TEAM
"""
today=datetime.date.today()
text='{today.month}/{today.day}/{today.year}'.format(today=today)
def make_messages(names,amounts):
message=[]
if len(names)==len(amounts):
i=0
for name in names:
name=name[0].upper()+name[1:].lower()
new_msg=unf_message.format(name=name,date=text,total=amounts[i])
i=i+1
print(new_msg)
make_messages(default_name,default_amounts)
class animal():
def __init__(self,name,color,kind):
self.name=name
self.color=color
self.kind=kind
class Animal():
name="Whisper"
color="Red"
kind="Birds"
class Bird(animal):
size=20
class Bird(animal):
def __init__(self,size):
self.size=size
dog=Animal
dog.color="red"
name="Lucky"
color="Black"
class Dog():
name();
color();
height()
import datetime
class MessageUser():
user_details=[]
messages=[]
base_message="""Hi there {name}!!!
Thanks for a great work.
{date} was a good day
Your purchuase {total}
Support TEAM
"""
def add_user(self,name,amount,email=None):
name=name[0].upper()+name[1:].lower()
today=datetime.date.today()
date_text='{today.month}/{today.day}/{today.year}'.format(today=today)
amount="%.2f"%(amount)
detail={
"name":name,
"amount":amount,
"date":date_text
}
if email is not None:
detail["email"]=email
self.user_details.append(detail)
def get_details(self):
return self.user_details
def make_messages(self):
if len(self.user_details)>0:
for detail in self.get_details():
name=detail["name"]
date=detail["date"]
amount=detail["amount"]
message=self.base_message
new_msg=message.format(
name=name,
date=date,
total=amount
)
self.messages.append(new_msg)
return self.messages
return []
pizdez=MessageUser()
pizdez.add_user("igor",23.4)
pizdez.add_user("stePhan",2323.232)
pizdez.add_user("YuREZS",2323.232,email="yura@rambler.ru")