Skip to content

Instantly share code, notes, and snippets.

@TramPamPam
Last active November 24, 2016 10:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TramPamPam/3172d8c438920555b9d750c43ac7263c to your computer and use it in GitHub Desktop.
Save TramPamPam/3172d8c438920555b9d750c43ac7263c to your computer and use it in GitHub Desktop.
Getting acquaintance with 'def' in Python
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