forked from tdwojak/Python2017
Praca domowa nr 2
Rozwiązanie - nr indeksu 45146
This commit is contained in:
parent
c723ed6bb1
commit
16cd898241
@ -1,13 +1,26 @@
|
||||
"""
|
||||
**ćwiczenie 2**
|
||||
Napisz generator, który będzie zwracać ``n`` kolejnych liczb ciągu Fibonacciego (``F(0)=1, F(1)=1, FN=F(N-1) + F(N-2)``).
|
||||
"""
|
||||
|
||||
def Fibogen(n):
|
||||
if n == 0:
|
||||
ret = yield 1
|
||||
yield 1
|
||||
if n == 1:
|
||||
ret = yield 1
|
||||
for i in range(n+1):
|
||||
ret = yield (Fibogen(n-2) + Fibogen(n-1))
|
||||
return ret
|
||||
yield 1
|
||||
yield 1
|
||||
if n >= 2 :
|
||||
i, j = 1, 1
|
||||
yield 1
|
||||
yield 1
|
||||
for k in range(2, n):
|
||||
f = i + j
|
||||
i = j
|
||||
j = f
|
||||
yield f
|
||||
|
||||
for i in Fibogen(4):
|
||||
|
||||
for i in Fibogen(15):
|
||||
print(i)
|
||||
|
||||
|
||||
|
@ -1,21 +1,19 @@
|
||||
def Fibogen(n):
|
||||
if n == 0:
|
||||
yield 1
|
||||
if n == 1:
|
||||
yield 1
|
||||
yield 1
|
||||
if n >= 2 :
|
||||
i, j = 1, 1
|
||||
yield 1
|
||||
yield 1
|
||||
for k in range(2, n):
|
||||
f = i + j
|
||||
i = j
|
||||
j = f
|
||||
yield f
|
||||
"""
|
||||
**ćwiczenie 3**
|
||||
Strona ``https://api.fixer.io/latest`` udostępnia kursy różnych walut w stosunku do euro. Napisz skrypt, który:
|
||||
* pobierze zawartość JSONa. Wykorzystaj bibliotekę ``requests`` (http://docs.python-requests.org/en/master/).
|
||||
* korzystając z biblioteki ``json`` przekształć go do obiketu typu JSON.
|
||||
* Wyświetl wartość kursu EUR do PLN.
|
||||
"""
|
||||
|
||||
|
||||
for i in Fibogen(15):
|
||||
print(i)
|
||||
|
||||
import requests as rr
|
||||
import json as jsn
|
||||
|
||||
url_rates = "https://api.fixer.io/latest"
|
||||
website = rr.get(url_rates)
|
||||
json_s = website.text
|
||||
ratesJson = jsn.loads(json_s)
|
||||
#print(ratesJson)
|
||||
#print("EUR/PLN = ", ratesJson['rates']['PLN'])
|
||||
print(ratesJson['rates']['PLN'])
|
||||
|
Loading…
Reference in New Issue
Block a user