Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- =================LAB9=================
- Polecenie 1
- for i in range(1, 100):
- if(i % 15 == 0):
- print("FizzBuzz")
- elif(i % 3 == 0):
- print("Fizz")
- elif(i % 5 == 0):
- print("Buzz")
- else:
- print(i)
- Polecenie 2
- def numer_to_word(n):
- liczby = {'1' : "jeden",
- '2' : "dwa",
- '3' : "trzy",
- '4' : "cztery",
- '5' : "pięć",
- '6' : "sześć",
- '7' : "siedem",
- '8' : "osiem",
- '9' : "dziewięć",
- '0' : "zero"}
- for num in str(n):
- print(liczby[num], end=' ')
- Polecenie 3
- def arabic_to_roman():
- number = int(input('Podaj liczbe: '))
- num_in_roman = ''
- arabic_roman={1000: 'M',
- 900: 'CM',
- 500: 'D',
- 400: 'CD',
- 100: 'C',
- 90: 'XC',
- 50: 'L',
- 40: 'XL',
- 10: 'X',
- 9: 'IX',
- 5: 'V',
- 4: 'IV',
- 1: 'I'
- }
- for arabic, roman in arabic_roman.items():
- num_in_roman += number // arabic * roman
- number %= arabic
- print(num_in_roman)
- =================LAB10=================
- Polecenie 1
- def czyPalindrom():
- while (1):
- slowo = str(input("Wpisz slowo aby sprawdzic, czy jest palindromem: ")).lower()
- if (slowo == slowo[::-1]):
- print("Palindrom!")
- else:
- print("Podane slowo nie jest palindromem.")
- Polecenie 2
- def szyfrowanie(haslo, podstawaSzyfru):
- hasloZaszyfrowane = ""
- print(chr(65))
- for i in range(len(haslo)):
- hasloZaszyfrowane += chr(65 + ((ord(haslo[i]) + podstawaSzyfru - 65) % 25))
- return hasloZaszyfrowane
- def szyfrCezara():
- while (1):
- haslo = str(input("Podaj haslo do zaszyfrowania: "))
- podstawaSzyfru = int(input("Podaj podstawe szyfru: "))
- haslo = szyfrowanie(haslo, podstawaSzyfru)
- print(haslo)
- Polecenie 3
- def losowanieTablicyRejestracyjnej():
- while (1):
- tablicaRejestracyjna = "LU "
- input("Nacisnij Enter, aby wylosowac tablice: ")
- for i in range(6):
- if randint(0, 1):
- tablicaRejestracyjna += chr(randint(65, 90))
- else:
- tablicaRejestracyjna += chr(randint(48, 57))
- print(tablicaRejestracyjna)
- Polecenie 4
- def rzymskieNaArabskie():
- while(1):
- liczbaRzymska = str(input("Podaj liczbe w systemie rzymskim: ")).upper()
- liczbaArabska = 0
- slownikRzymskie = \
- {'I': 1,
- 'V': 5,
- 'X': 10,
- 'L': 50,
- 'C': 100,
- 'D': 500,
- 'M': 1000}
- try:
- for i in range(len(liczbaRzymska) - 1):
- if slownikRzymskie[liczbaRzymska[i]] < slownikRzymskie[liczbaRzymska[i + 1]]:
- liczbaArabska += slownikRzymskie[liczbaRzymska[i]] * -1
- continue
- liczbaArabska += slownikRzymskie[liczbaRzymska[i]]
- liczbaArabska += slownikRzymskie[liczbaRzymska[-1]]
- print(liczbaArabska)
- except KeyError:
- print("Podano liczbe w niepoprawnym formacie. ")
- =================LAB11=================
- Polecenie 1
- class GeoPoint:
- def __init__(self, longitude: float, latitude: float):
- self.longitude = longitude
- self.latitude = latitude
- def longitude(self):
- return self.longitude
- def latitude(self):
- return self.latitude
- def __eq__(self, other):
- return (
- self.longitude == other.longitude and self.latitude == other.latitude)
- def __str__(self):
- return f'{{lat: {self.latitude}, lon: {self.longitude}}}.'
- def task_1():
- point_1 = GeoPoint(51.21782, 22.54583)
- point_2 = GeoPoint(51.21782, 22.54583)
- print(point_1 == point_2)
- print(point_1, point_2)
- Polecenie 2
- from math import radians, cos, sin, asin, sqrt
- class GeoPoint:
- def __init__(self, longitude: float, latitude: float):
- self.longitude = longitude
- self.latitude = latitude
- def longitude(self):
- return self.longitude
- def latitude(self):
- return self.latitude
- def haversine(lon1: float, lat1: float, lon2: float, lat2: float):
- """Calculate the great circle distance between two points on earth (specified in decimal degrees) """
- lon1, lat1, lon2, lat2 = map(radians, [lon1, lat1, lon2, lat2])
- dlon = lon2 - lon1
- dlat = lat2 - lat1
- a = sin(dlat / 2) ** 2 + cos(lat1) * cos(lat2) * sin(dlon / 2) ** 2
- c = 2 * asin(sqrt(a))
- meters = 6371000 * c
- return meters
- def print_geoPoint_list(geo_point_list: list):
- for point in geo_point_list:
- print(f'{point.longitude: .5f}, {point.latitude :.5f}')
- def sort_geoPoint_list(geo_point_list: list, point_sorted_by):
- geo_point_list.sort(key=lambda x: GeoPoint.haversine(x.longitude, x.latitude, point_sorted_by.longitude,
- point_sorted_by.latitude))
- def __eq__(self, other):
- return (self.longitude == other.longitude and self.latitude == other.latitude)
- def __str__(self):
- return f'{{lat: {self.latitude}, lon: {self.longitude}}}.'
- def __repr__(self):
- return f'{self.longitude} {self.latitude}'
- def task_2():
- point_1 = GeoPoint(51.21782, 22.54583)
- point_2 = GeoPoint(51.21353, 22.54142)
- point_3 = GeoPoint(51.21483, 22.52527)
- point_4 = GeoPoint(51.22352, 22.55640)
- point_sorted_by = GeoPoint(51.21167, 22.5222)
- points_list = [point_1, point_2, point_3, point_4]
- GeoPoint.sort_geoPoint_list(points_list, point_sorted_by)
- GeoPoint.print_geoPoint_list(points_list)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement