Created
July 30, 2017 11:29
-
-
Save rostyq/8cc49c24773ac5a599fcb248cfa7f165 to your computer and use it in GitHub Desktop.
Exercise on www.practicepython.org
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_user_int(msg): | |
''' | |
Return integer from user. | |
:param msg: | |
:return user_input: | |
''' | |
user_input = input(msg) | |
try: | |
user_input = int(user_input) | |
except: | |
print("Something wrong...") | |
return user_input | |
def get_fibonacci(count=3): | |
""" | |
Return list with Fibonacci numbers | |
:param count: | |
:return fibonacci_list: | |
""" | |
i = 2 | |
fibonacci_list = [1, 1] | |
while i < count: | |
fibonacci_list.append(sum(fibonacci_list[-2:])) | |
i += 1 | |
return fibonacci_list | |
count = get_user_int("Input a count of Fibonacci numbers ->") | |
print(get_fibonacci(count)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment