Last active
November 24, 2016 10:00
-
-
Save TramPamPam/3172d8c438920555b9d750c43ac7263c to your computer and use it in GitHub Desktop.
Getting acquaintance with 'def' in Python
This file contains 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
alphabet = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'] | |
alphabetLength = len(alphabet) | |
def get_alphabet_till(length): | |
# Validate input | |
# 1) Check for type: | |
if not (type(length) is int): #type of length must be int | |
return "Sorry, I expect int" | |
# 2) Check range: | |
if length > alphabetLength: #length should be equal or less of letters count | |
return "Sorry, there not so much letters in alphabet" | |
result = "" | |
for i in range(length): | |
result += alphabet[i] | |
return result | |
def repeat_alphabet(howLong): | |
# Validate input | |
# Check for type: | |
if not (type(howLong) is int): #type of howLong must be int | |
return "Sorry, I expect int" | |
result = "" | |
while howLong > 0: | |
if howLong > alphabetLength: | |
result += get_alphabet_till(alphabetLength) | |
else: | |
result += get_alphabet_till(howLong) | |
howLong -= alphabetLength | |
return result | |
print(repeat_alphabet(int(input("how many letters? ")))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment