samedi 27 mars 2021

How to find the longest English Word that can be displayed in a seven segment display?

I was inspired from Tom Scott's Video about seven segment displays (link Below), and set out to find out the longest english word that can be displayed in a seven segment display using python, I am a beginner and the best code I could write was this:

var1=open("c:/Users/Choutisha Banerjee/Desktop/words.txt", "r")
list1=var1.readlines()
list2 = ["g","k","m","q","v","w","x","z"]
longword=" "
for n in list1:
    if len(n)>len(longword):
        for x in n:
         if x in list2:
             continue
    else:
         longword=n
else:
    continue
print(longword)

It is printing the longest word present in the list. It would be a great help if you could inform me about where I went wrong.

(I used a premade list of all english words i.e. words.txt)

Link to Tom's Video: https://youtu.be/zp4BMR88260

link to .py (just in case you need it): https://drive.google.com/file/d/1M78YP67VkqC2Uz3mbQxcqk15vO7mW6Rx/view?usp=sharing

Please Help Thank you.

Aucun commentaire:

Enregistrer un commentaire