Checking if a word chain is correct I have made a code to check if a word chain is correct or not.


The first input is the amount of words that will following
The first and last letter of every word should be the same
Therefore a chain can look like this:  Alaska - baobab - Cadillac - drievuldigheid -  Enigma -  fotografencollectief - Gasthuisberg


If the chain is incorrect the output should be the wrong word, else it should be 'word chain is correct'.



As you'll be thinking, this is an excercise for school. I have exam in a few days and I'm doing some excercises.

My code looks like this:

import string
words = int(input())
alphabet = string.ascii_lowercase
output = ''

for i in range(words):
    woord = input()

    #for the first word
    if i == 0:
        #make that the alpabet last letter is the starting letter of the word
        alphabet = alphabet[alphabet.index(woord[0].lower())+1:] + alphabet[0:alphabet.index(woord[0].lower())+1]

    #check if the last letter of the word is equal to the first  letter
    #check if the last letter of the word is equal to the last letter of the alphabet
    if woord[0].lower() == woord[-1].lower() and alphabet[-1] == woord[0].lower():
        #if so: move the alphabet one Index
        alphabet = alphabet[1:] + alphabet[:1]

    elif output == '':
        output = woord

if output == '':
    print('word chain is correct')
else:
    print(output)


I'm wondering if there is some room for improvement, as it looks my code isn't pythonic at all.
A few remarks:


You can do the .lower() one time by using woord = input().lower()
You could check if they are in alphabetic order by keeping track of the    previous one like this:

previouschar=''
for s in ('aaa', 'bbb', 'ddd', 'efe', 'geg'):
    if previouschar != '' and ord(s[0]) != ord(previouschar) + 1:
        print('Out of order')
    previouschar = s[0]