1
0
forked from tdwojak/Python2017

lab 3 filled

This commit is contained in:
s45163 2018-01-20 19:56:37 +01:00
parent 3fa9c4f31f
commit f3e7e6f696

89
labs03/lab3.py Normal file
View File

@ -0,0 +1,89 @@
import requests
from weather import Weather
import glob
import re
def fibb(n):
liczby = [0,1]
for i in range(1,n):
liczby.append(liczby[-1]+liczby[-2])
return liczby
def EUR_PLN_rate():
value = requests.get('https://api.fixer.io/latest')
asJson = value.json()
return asJson['rates']['PLN']
def niezmiennosc():
lista = ['a', 'b', 'c']
idPrzed = id(lista)
lista.append('d')
idPo = id(lista)
lista2 = lista.append('e')
idPoZPrzypisaniem = id(lista2)
print(
'Lista przed modyfikacja: {}, po modyfikacji: {}, obiekt niezmienny: {}, po przypisaniu nowy obiekt: {}'.format(
idPrzed, idPo, idPrzed != idPo, idPrzed != idPoZPrzypisaniem))
napis = 'To jest napis'
idPrzed = id(napis)
napis = napis + 'zmieniony'
idPo = id(napis)
print(
'Napis przed modyfikacja: {}, po modyfikacji: {}, obiekt niezmienny: {}'.format(idPrzed, idPo, idPrzed != idPo))
numerek = 0.123
idPrzed = id(numerek)
numerek = numerek + 0.1
idPo = id(numerek)
print('Numerek przed modyfikacja: {}, po modyfikacji: {}, obiekt niezmienny: {}'.format(idPrzed, idPo,
idPrzed != idPo))
def toCelsius(tempF):
return ((tempF-32)*5/9)
def weatherApi():
weather = Weather()
location = weather.lookup_by_location('poznan')
condition = location.condition()
tempF = int(condition.temp())
tempC = (tempF-32)*5/9
print(tempC)
lowest = location.forecast()[0]
for forecast in location.forecast():
if forecast.low() < lowest.low():
lowest = forecast
print(lowest.date())
print(toCelsius(int(lowest.low())))
def highestTrained():
highest_bleu = 0
higlest_file = ''
for file in glob.glob('./scores/*.bleu'):
with open(file) as f:
bleu = re.match(r'BLEU\s=\s(?P<bleu_val>\d{1,2}\.\d{1,2})', f.readline(12))
if bleu:
potential_highest = float(bleu.group('bleu_val'))
if potential_highest > highest_bleu:
highest_bleu = potential_highest
higlest_file = f.name
print(higlest_file)
if __name__ == '__main__':
# cwiczenie 1
niezmiennosc()
# cwiczenie 2
print(fibb(19))
# cwiczenie 3
print(EUR_PLN_rate())
# cwiczenie 4
weatherApi()
# cwiczenie 5
highestTrained()