Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Python – Going over a list of words in python with for loop

Getting back into programming, I’ve been messing with this for a while now sure it’s something super simple or maybe I have things set-up completely wrong.

It’s an issue with it not iterating over the rest of the list.

So whenever you run the code you enter a file extension i.e. "File.jpg" and it comes back with image, but if you enter any of the other image types it returns application.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

def main():
    file = input("File name:")

    extension(file)


def extension(s):
    split = (s.split("."))
    join_s = (''.join(split[1]))
    image_e = ['jpg', 'gif', 'jpeg', '.png']

    for i in image_e:
        print(image_e)
        if i == join_s:
            return print("Image/")
        else:
            return print("Application")


main()

I haven’t got to the part of implementing the application formats just yet, but I am sure once I figure this bit out it shouldn’t be any sort of issue.

>Solution :

Change your if statement to "if join_s in image_e:" should work. Also,"png" inside image_e should not have a "." infront of it

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading