Advertisement
mikolajmki

python_wszystkie_zadania

Jun 13th, 2022
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 6.04 KB | None | 0 0
  1. =================LAB9=================
  2.  
  3. Polecenie 1
  4.  
  5. for i in range(1, 100):
  6.     if(i % 15 == 0):
  7.         print("FizzBuzz")
  8.     elif(i % 3 == 0):
  9.         print("Fizz")
  10.     elif(i % 5 == 0):
  11.         print("Buzz")
  12.     else:
  13.         print(i)
  14.  
  15. Polecenie 2
  16.  
  17. def numer_to_word(n):
  18.     liczby = {'1' : "jeden",
  19.               '2' : "dwa",
  20.               '3' : "trzy",
  21.               '4' : "cztery",
  22.               '5' : "pięć",
  23.               '6' : "sześć",
  24.               '7' : "siedem",
  25.               '8' : "osiem",
  26.               '9' : "dziewięć",
  27.               '0' : "zero"}
  28.     for num in str(n):
  29.         print(liczby[num], end=' ')
  30.  
  31. Polecenie 3
  32.  
  33. def arabic_to_roman():
  34.     number = int(input('Podaj liczbe: '))
  35.    
  36.     num_in_roman = ''
  37.     arabic_roman={1000: 'M',
  38.                     900: 'CM',
  39.                     500: 'D',
  40.                     400: 'CD',
  41.                     100: 'C',
  42.                     90: 'XC',
  43.                     50: 'L',
  44.                     40: 'XL',
  45.                     10: 'X',
  46.                     9: 'IX',
  47.                     5: 'V',
  48.                     4: 'IV',
  49.                     1: 'I'
  50.                     }
  51.     for arabic, roman in arabic_roman.items():
  52.         num_in_roman += number // arabic * roman
  53.         number %= arabic
  54.     print(num_in_roman)
  55.  
  56. =================LAB10=================
  57.  
  58. Polecenie 1
  59.  
  60. def czyPalindrom():
  61.  
  62.     while (1):
  63.         slowo = str(input("Wpisz slowo aby sprawdzic, czy jest palindromem: ")).lower()
  64.  
  65.         if (slowo == slowo[::-1]):
  66.             print("Palindrom!")
  67.         else:
  68.             print("Podane slowo nie jest palindromem.")
  69.  
  70. Polecenie 2
  71.  
  72. def szyfrowanie(haslo, podstawaSzyfru):
  73.  
  74.     hasloZaszyfrowane = ""
  75.  
  76.     print(chr(65))
  77.     for i in range(len(haslo)):
  78.         hasloZaszyfrowane += chr(65 + ((ord(haslo[i]) + podstawaSzyfru - 65) % 25))
  79.  
  80.     return hasloZaszyfrowane
  81.  
  82.  
  83.  
  84. def szyfrCezara():
  85.  
  86.     while (1):
  87.         haslo = str(input("Podaj haslo do zaszyfrowania: "))
  88.         podstawaSzyfru = int(input("Podaj podstawe szyfru: "))
  89.  
  90.         haslo = szyfrowanie(haslo, podstawaSzyfru)
  91.         print(haslo)
  92.  
  93. Polecenie 3
  94.  
  95. def losowanieTablicyRejestracyjnej():
  96.  
  97.     while (1):
  98.         tablicaRejestracyjna = "LU "
  99.         input("Nacisnij Enter, aby wylosowac tablice: ")
  100.  
  101.         for i in range(6):
  102.             if randint(0, 1):
  103.                 tablicaRejestracyjna += chr(randint(65, 90))
  104.             else:
  105.                 tablicaRejestracyjna += chr(randint(48, 57))
  106.  
  107.         print(tablicaRejestracyjna)
  108.  
  109. Polecenie 4
  110.  
  111. def rzymskieNaArabskie():
  112.  
  113.     while(1):
  114.  
  115.         liczbaRzymska = str(input("Podaj liczbe w systemie rzymskim: ")).upper()
  116.         liczbaArabska = 0
  117.        
  118.         slownikRzymskie = \
  119.             {'I': 1,
  120.              'V': 5,
  121.              'X': 10,
  122.              'L': 50,
  123.              'C': 100,
  124.              'D': 500,
  125.              'M': 1000}
  126.  
  127.         try:
  128.             for i in range(len(liczbaRzymska) - 1):
  129.                 if slownikRzymskie[liczbaRzymska[i]] < slownikRzymskie[liczbaRzymska[i + 1]]:
  130.                     liczbaArabska += slownikRzymskie[liczbaRzymska[i]] * -1
  131.                     continue
  132.                 liczbaArabska += slownikRzymskie[liczbaRzymska[i]]
  133.  
  134.             liczbaArabska += slownikRzymskie[liczbaRzymska[-1]]
  135.  
  136.             print(liczbaArabska)
  137.         except KeyError:
  138.             print("Podano liczbe w niepoprawnym formacie. ")
  139.  
  140. =================LAB11=================
  141.  
  142. Polecenie 1
  143.  
  144. class GeoPoint:
  145.     def __init__(self, longitude: float, latitude: float):
  146.         self.longitude = longitude
  147.         self.latitude = latitude
  148.  
  149.     def longitude(self):
  150.         return self.longitude
  151.  
  152.     def latitude(self):
  153.         return self.latitude
  154.  
  155.     def __eq__(self, other):
  156.         return (
  157.                 self.longitude == other.longitude and self.latitude == other.latitude)
  158.  
  159.     def __str__(self):
  160.         return f'{{lat: {self.latitude}, lon: {self.longitude}}}.'
  161.  
  162.  
  163. def task_1():
  164.     point_1 = GeoPoint(51.21782, 22.54583)
  165.     point_2 = GeoPoint(51.21782, 22.54583)
  166.  
  167.     print(point_1 == point_2)
  168.     print(point_1, point_2)
  169.  
  170. Polecenie 2
  171.  
  172. from math import radians, cos, sin, asin, sqrt
  173.  
  174. class GeoPoint:
  175.     def __init__(self, longitude: float, latitude: float):
  176.         self.longitude = longitude
  177.         self.latitude = latitude
  178.  
  179.     def longitude(self):
  180.         return self.longitude
  181.  
  182.     def latitude(self):
  183.         return self.latitude
  184.  
  185.     def haversine(lon1: float, lat1: float, lon2: float, lat2: float):
  186.         """Calculate the great circle distance between two points on earth (specified in decimal degrees) """
  187.         lon1, lat1, lon2, lat2 = map(radians, [lon1, lat1, lon2, lat2])
  188.  
  189.         dlon = lon2 - lon1
  190.         dlat = lat2 - lat1
  191.         a = sin(dlat / 2) ** 2 + cos(lat1) * cos(lat2) * sin(dlon / 2) ** 2
  192.         c = 2 * asin(sqrt(a))
  193.  
  194.         meters = 6371000 * c
  195.         return meters
  196.  
  197.     def print_geoPoint_list(geo_point_list: list):
  198.         for point in geo_point_list:
  199.             print(f'{point.longitude: .5f}, {point.latitude :.5f}')
  200.  
  201.     def sort_geoPoint_list(geo_point_list: list, point_sorted_by):
  202.         geo_point_list.sort(key=lambda x: GeoPoint.haversine(x.longitude, x.latitude, point_sorted_by.longitude,
  203.                                                              point_sorted_by.latitude))
  204.  
  205.     def __eq__(self, other):
  206.         return (self.longitude == other.longitude and self.latitude == other.latitude)
  207.  
  208.     def __str__(self):
  209.         return f'{{lat: {self.latitude}, lon: {self.longitude}}}.'
  210.  
  211.     def __repr__(self):
  212.         return f'{self.longitude} {self.latitude}'
  213.  
  214.  
  215. def task_2():
  216.     point_1 = GeoPoint(51.21782, 22.54583)
  217.     point_2 = GeoPoint(51.21353, 22.54142)
  218.     point_3 = GeoPoint(51.21483, 22.52527)
  219.     point_4 = GeoPoint(51.22352, 22.55640)
  220.  
  221.     point_sorted_by = GeoPoint(51.21167, 22.5222)
  222.     points_list = [point_1, point_2, point_3, point_4]
  223.     GeoPoint.sort_geoPoint_list(points_list, point_sorted_by)
  224.     GeoPoint.print_geoPoint_list(points_list)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement