• API
• FAQ
• Tools
• Archive
daily pastebin goal
53%
SHARE
TWEET

# python

a guest Jun 13th, 2018 50 Never
ENDING IN00days00hours00mins00secs

1. Python Lab1
2. 1:
3. text = input("Podaj tekst: ")
4. for x in text:
5.     print (x)
6. 2:
7. text = input("Podaj tekst: ")
8. for x in text:
9.     print (ord(x))
10. 3:
11. import sys
12.
13. if len(sys.argv) > 1:
14.     try:
15.         tabSize = int(sys.argv[1])
16.     except:
17.         print("Nie liczba")
18.     for i in range(0, tabSize+1):
19.         print('')
20.         for j in range(0, tabSize+1):
21.             print(i,'x',j,'=',i*j)
22. else:
23.     print("Brak argumentu")
24. 4:
25. import random
26.
27. randNum = random.randrange(0,10)
28. print(randNum)
29. win = False
30. for x in range(0,5):
31.     choice = input("Podaj liczbe z przedzialu 0-10: ")
32.     if randNum == int(choice):
33.         win = True
34.         break
35. if win == True:
36.     print("Win")
37. else:
38.     print("Lost")
39. 5:
40. import sys
41.
42. def checkPESEL(pesel):
43.     if len(pesel) != 11:
44.         print("Za krotki PESEL")
45.         sys.exit()
46.     try:
47.         check = int(pesel[0]) + 3*int(pesel[1]) + 7*int(pesel[2]) + 9*int(pesel[3]) + int(pesel[4]) + 3*int(pesel[5]) + 7*int(pesel[6]) + 9*int(pesel[7]) + int(pesel[8]) + 3*int(pesel[9]) + int(pesel[10])
48.         check = str(check)
49.         if check[len(check)-1] == '0':
50.             print("Prawidlowy PESEL")
51.             yearEnd = pesel[0] + pesel[1]
52.             monthTmp = pesel[2] + pesel[3]
53.             day = pesel[4] + pesel[5]
54.             month = int(monthTmp) - 20
55.             if month > 12 and month < 40:
56.                 month = month - 20
57.                 yearBeg = '21'
58.             elif month > 40 and month < 60:
59.                 month = month - 40
60.                 yearBeg = '22'
61.             elif month < 0:
62.                 month = month + 20
63.                 yearBeg = '19'
64.             elif month > 60:
65.                 month = month - 60
66.                 yearBeg = '18'
67.             else:
68.                 yearBeg = '20'
69.             print("Data urodzenia: ",day,'-',month,'-',yearBeg+yearEnd)
70.             if(int(pesel[9])%2 == 0):
71.                 print("K")
72.             else:
73.                 print("M")
74.             return True
75.         else:
76.             print("Nieprawidlowy PESEL")
77.             return False
78.     except:
80.         return False
81. if len(sys.argv)==2:
82.     checkPESEL(sys.argv[1])
83. 6:
85. import random
86.
87. yearBeg = random.randrange(18,22)
88. yearEnd = random.randrange(0,99)
89. month = random.randrange(1,12)
90. if month == 2:
91.     if (int(str(yearBeg)+str(yearEnd)) % 4 == 0) and (int(str(yearBeg)+str(yearEnd)) % 100 != 0) or (int(str(yearBeg)+str(yearEnd)) % 400 == 0):
92.         endRange = 29
93.     else:
94.         endRange = 28
95. elif month in [1, 3, 5, 7, 8, 10, 12]:
96.     endRange = 31
97. elif month in [4, 6, 9, 11]:
98.     endRange = 30
99. day = random.randrange(1, endRange)
100. if yearBeg == 18:
101.     month += 80
102. elif yearBeg == 20:
103.     month += 20
104. elif yearBeg == 21:
105.     month += 40
106. elif yearBeg == 22:
107.     month += 60
108. yearBeg = str(yearBeg)
109. if yearEnd < 10:
110.     yearEnd = str(0) + str(yearEnd)
111. else:
112.     yearEnd = str(yearEnd)
113. if month < 10:
114.     month = str(0) + str(month)
115. else:
116.     month = str(month)
117. if day < 10:
118.     day = str(0) + str(day)
119. else:
120.     day = str(day)
121. number7 = random.randrange(0,9)
122. number8 = random.randrange(0,9)
123. number9 = random.randrange(0,9)
124. gender = random.randrange(0,9)
125. check = str(9*int(yearEnd[0]) + 7*int(yearEnd[1]) + 3*int(month[0]) + int(month[1]) + 9*int(day[0]) + 7*int(day[1]) + 3*number7 + number8 + 9*number9 + 7*gender)
126. lastNum = check[len(check)-1]
127. pesel = yearEnd + month + day + str(number7) + str(number8) + str(number9) + str(gender) + lastNum
128. print(pesel)
130. 7:
131. import string
132. import random
133. import sys
134.
135. if len(sys.argv) == 1:
136.     sys.exit()
137. print(''.join(random.choices(string.ascii_lowercase+string.ascii_uppercase + string.digits, k=int(sys.argv[1]))))
138. Python Lab2
139. 1:
140. import sys
141. import string
142. if len(sys.argv) < 2:
144.     sys.exit()
145. file = open(sys.argv[1], "r")
147. file.close()
148. file = open(sys.argv[1], "w")
149. file.write(text.lower())
150. file.close()
151. 2:
152. import sys
153. import string
154.
155. if len(sys.argv) < 3:
157.     sys.exit()
159. if sys.argv[2] == '1':
160.     file = open(sys.argv[1],"w",newline='\r\n')
161. else:
162.     file = open(sys.argv[1],"w",newline='\n')
163. file.write(text)
164. file.close()
165. 3:
166. import sys
167.
168. def zliczLinie(file):
169.     lines=0
170.     with open(file,'r') as f:
171.         for line in f:
172.             lines += 1
173.     return lines
174. def zliczZnaki(file):
175.     signs=0
176.     with open(file,'r') as f:
177.         for line in f:
178.             for i in line:
179.                 signs += 1
180.     return signs
181. if(len(sys.argv) == 2):
182.     print (zliczLinie(sys.argv[1]))
183.     print (zliczZnaki(sys.argv[1]))
184. 4:
185. import sys
187.
188. if len(sys.argv) < 2:
190.     sys.exit()
192. lineNum=0
193. longLine=0
194. tmp=0
195. signNum=0
196. with open(sys.argv[1],'r') as f:
197.     for line in f:
198.         lineNum += 1
199.         for x in line:
200.             tmp+=1
201.         if(tmp>signNum):
202.             signNum=tmp
203.             lineTxt=line
204.             longLine=lineNum
205.         tmp=0
206. print(str(longLine)+': '+lineTxt)
207. 5:
208. import sys
209. import random
210. import string
211.
212. if len(sys.argv) < 2:
214.     sys.exit()
215. def random_line():
217.     return random.choice(lines) + ' '
218. word = ''
219. for x in range(0,int(sys.argv[1])):
220.     word += random_line()
221. word = word[0].upper() + word[1:len(word)-1] + '.'
222. print(word)
223. 6:
224. import sys
225. from collections import Counter
226.
227. if len(sys.argv) != 2:
229. with open(sys.argv[1], 'r') as f:
231. for i in wordcount.items():
232.     print(i)
233. 7:
234. import sys
235. from collections import Counter
236.
237. if len(sys.argv) != 2: