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 List Loops, Print Satellite Names according to Number Enetered after Comma

UserInput: (“LANDSAT8,5,MODIS,3,SENTINAL2,6”).
User entered three satellites name and instruct the program that how many images of that
particular satellite should be downloaded. In this example, there are three pairs;

  1. LANDSAT8,5
  2. MODIS,3
  3. SENTINAL2,6

Preferred Output should be like:

Program Output:
LANDSAT8 image 1 downloaded
LANDSAT8 image 2 downloaded
LANDSAT8 image 3 downloaded
LANDSAT8 image 4 downloaded
LANDSAT8 image 5 downloaded
MODIS image 1 downloaded
MODIS image 2 downloaded
MODIS image 3 downloaded
SENTINAL2 image 1 downloaded
SENTINAL2 image 2 downloaded
SENTINAL2 image 3 downloaded
SENTINAL2 image 4 downloaded
SENTINAL2 image 5 downloaded
SENTINAL2 image 6 downloaded

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

>Solution :

I think this may be what you’re trying to do:

user_input = "LANDSAT8,5,MODIS,3,SENTINAL2,6"

tokens = user_input.split(',')

for s, d in zip(tokens[::2], map(int, tokens[1::2])):
    for i in range(d):
        print(f'{s} image {i+1} downloaded')

Output:

LANDSAT8 image 1 downloaded
LANDSAT8 image 2 downloaded
LANDSAT8 image 3 downloaded
LANDSAT8 image 4 downloaded
LANDSAT8 image 5 downloaded
MODIS image 1 downloaded
MODIS image 2 downloaded
MODIS image 3 downloaded
SENTINAL2 image 1 downloaded
SENTINAL2 image 2 downloaded
SENTINAL2 image 3 downloaded
SENTINAL2 image 4 downloaded
SENTINAL2 image 5 downloaded
SENTINAL2 image 6 downloaded
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