Advertisement
Guest User

Untitled

a guest
Jun 25th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.79 KB | None | 0 0
  1. ####################################################STRING FUNCTIONS
  2. #zad 16
  3. message = input("Podaj wiadomosc: ")
  4. key = int(input("ile znaków chcesz zamienić(1-26) "))
  5.  
  6. secret_message = ""
  7. for char in message:
  8. if char.isalpha():
  9. char_code = ord(char)
  10. char_code += key
  11. if char.isupper():
  12. if char_code > ord('Z'):
  13. char_code -= 26
  14. if char_code < ord('A'):
  15. char_code += 26
  16. else:
  17. if char_code > ord('z'):
  18. char_code -= 26
  19. if char_code < ord('a'):
  20. char_code += 26
  21. secret_message += chr(char_code)
  22. else:
  23. secret_message += char
  24. print("Encrypted : ", secret_message)
  25. key = -key
  26. orig_message = ""
  27.  
  28. for char in secret_message:
  29. if char.isalpha():
  30. char_code = ord(char)
  31. char_code += key
  32. if char.isupper():
  33. if char_code > ord('Z'):
  34. char_code -= 26
  35. if char_code < ord('A'):
  36. char_code += 26
  37. else:
  38. if char_code > ord ('z'):
  39. char_code -= 26
  40. if char_code < ord('a'):
  41. char_code += 26
  42. orig_message += chr(char_code)
  43. else:
  44. orig_message += char
  45. print("Decrypted : ", orig_message)
  46.  
  47. #zad 15
  48.  
  49. # new_string = input("Podaj stringa: ")
  50. # new_string = new_string.upper()
  51. # a_list = new_string.split()
  52. # for word in a_list:
  53. # print(word[0], end="")
  54. # print()
  55.  
  56. ####################################################EXCEPTIONS & STRINGS
  57. #zad 14
  58. # norm_string = (input("Podaj słowo do zaszyfrowania "))
  59. #
  60. # secret_string = ""
  61. #
  62. # for char in norm_string:
  63. # secret_string += str(ord(char) - 23)
  64. # print("Sekretna wiadomosc: ", secret_string)
  65. # norm_string = ""
  66. # for i in range(0, len(secret_string)-1, 2):
  67. # char_code = secret_string[i] + secret_string[i+1]
  68. # norm_string += chr(int(char_code)+23)
  69. # print("oryginalna wiadomosc: ", norm_string)
  70.  
  71. #zad 13
  72. # import random
  73. #
  74. # rand_num = random.randrange(10)
  75. # i = 1
  76. #
  77. # while (i != rand_num):
  78. # i += 1
  79. # while True:
  80. # try:
  81. # number = int(input("Zgadnij liczbe od 1 do 10: "))
  82. #
  83. # if number == rand_num:
  84. # print("Zgadłes")
  85. # break
  86. # except ValueError:
  87. # print("Nie podales liczby")
  88.  
  89. #zad 12
  90.  
  91. # while True:
  92. # try:
  93. # number = int(input("Prosze podaj liczbe: "))
  94. # break
  95. # except ValueError:
  96. # print("Nie podales liczby")
  97. #
  98. # except:
  99. # print("Wystapil nieznany blad")
  100. #
  101. # print("Dziekuje za podanie liczny, która wynosi: ", number)
  102.  
  103.  
  104.  
  105. ##################################################### LOOPS
  106.  
  107. #Zad 11
  108.  
  109. # tree_height = input ("How tall is the tree ")
  110. # tree_height = int(tree_height)
  111. # spaces = tree_height - 1
  112. # hashes = 1
  113. # stump_spaces = tree_height -1
  114. # while tree_height != 0:
  115. # for i in range(spaces):
  116. # print(' ', end="")
  117. # for i in range(hashes):
  118. # print('#', end="")
  119. # print()
  120. # spaces -= 1
  121. # hashes += 2
  122. # tree_height -= 1
  123. # for i in range(stump_spaces):
  124. # print(' ', end="")
  125. # print('#')
  126.  
  127.  
  128. #zad 10
  129. # i = 1
  130. #
  131. # while i <= 20:
  132. # if (i % 2) == 0:
  133. # i += 1
  134. # continue
  135. # if i == 15:
  136. # break
  137. #
  138. # print("Odd : ", i)
  139. # i += 1
  140.  
  141.  
  142. # #zad 9
  143. # import random
  144. # rand_num = random.randrange(100)
  145. # i = 1
  146. #
  147. # while (i !=rand_num):
  148. # i += 1
  149. #
  150. # print("Losowa wartosc to: ", rand_num)
  151.  
  152. #zad 8
  153. # money = input('Ile inwestujesz: ')
  154. # rate = input('Oprocenotwanie ')
  155. #
  156. # money = float(money)
  157. # rate = float(rate) *.01
  158. #
  159. # for i in range(10):
  160. # money = money + (money * rate)
  161. # print("Zarobek po 10 latach : {:.2f}".format(money))
  162.  
  163. #zad 7
  164. # your_float = input("podja liczbe zmiennoprzeczinkowa: ")
  165. # your_float = float(your_float)
  166. # print("Zaokraglij do 2 liczb po przecinku : {:.2f}".format(your_float))
  167.  
  168. #Zad 6
  169. # for i in range(1, 21):
  170. #
  171. # if((i % 2) !=0):
  172. # print("i = ", i)
  173.  
  174.  
  175. ##################################################### LOOPS
  176.  
  177.  
  178. #zad 5
  179.  
  180. # age = eval(input('Podaj wiek '))
  181. #
  182. # if age < 5:
  183. # print('u r too young for school')
  184. # elif (age == 5):
  185. # print("Go to kindergarten")
  186. # elif (age > 5) and (age <= 17):
  187. # grade = age - 5
  188. # print('Go to {} grade'.format(grade))
  189. # else:
  190. # print("Go to collage")
  191.  
  192. #zad 4
  193. #
  194. # age = eval(input('Podaj wiek '))
  195. #
  196. # if (age>= 1 and age <= 18):
  197. # print("Important Birthday1")
  198. # elif (age == 21) or (age == 50):
  199. # print('Important birthday2')
  200. # elif not(age<65):
  201. # print("Important Birthdays3")
  202. # else:
  203. # print("Sorry not important")
  204.  
  205. #zad3
  206. # num1, operator, num2 = input('Podaj rownanie ').split()
  207. #
  208. # num1 = int(num1)
  209. # num2 = int(num2)
  210. #
  211. # if operator == "+":
  212. # print("{} + {} = {}".format(num1,num2, num1 + num2))
  213. # elif operator == "-":
  214. # print("{} - {} = {}".format(num1, num2, num1 - num2))
  215. # elif operator == "*":
  216. # print("{} * {} = {}".format(num1, num2, num1 * num2))
  217. # elif operator == "/":
  218. # print("{} / {} = {}".format(num1, num2, num1 / num2))
  219. # else:
  220. # print("błędny format podaj +, -, * lub /")
  221.  
  222. # zad 2
  223. # miles = input('Podaj ilesc mil ')
  224. # miles = int(miles)
  225. # km = miles * 1.60934
  226. # print("{} miles equals {} kilometers".format(miles,km))
  227.  
  228. # zad1
  229. #
  230. # num1, num2 = input('Podaj 2 wartosci ').split()
  231. #
  232. # num1 = int(num1)
  233. # num2 = int(num2)
  234. #
  235. # sum = num1 + num2
  236. #
  237. # diff = num1 - num2
  238. #
  239. # prod = num1 * num2
  240. #
  241. # quot = num1 / num2
  242. #
  243. # remain = num1 % num2
  244. #
  245. # print("{} + {} = {}".format(num1,num2,sum))
  246. # print("{} - {} = {}".format(num1,num2,diff))
  247. # print("{} * {} = {}".format(num1,num2,prod))
  248. # print("{} / {} = {}".format(num1,num2,quot))
  249. # print("{} % {} = {}".format(num1,num2,remain))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement