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

How would I increase a integer value inside this loop?

Trying to increase an integer value

So basically I’m trying to increase "e" so everytime I input a new line it would go 0, 1 etc

My input would look like this

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

example1
example2
def no(paths: str):
    e = 0
    for path in paths.split(" "):
        print("            ItemListData(" + str(e) + ")=(ItemDefination=" + path + '")')
        e = e + 1

while True:
    paths = input()
    no(paths)

When I do this I get this:

ItemListData(0)=(ItemDefination=example1")
ItemListData(0)=(ItemDefination=example2")

What I want is this

ItemListData(0)=(ItemDefination=example1")
ItemListData(1)=(ItemDefination=example2")

>Solution :

Assuming you want to have the value e increase every time you execute the function, you can do this:

def no(paths: str, e: int):
    for path in paths.split(" "):
        print("            ItemListData(" + str(e) + ")=(ItemDefination=" + path + '")')

e = 0
while True:
    paths = input()
    no(paths, e)
    e += 1

The first two lines of output, with inputs as follows:

execute1 execute2

execute1
    ItemListData(0)=(ItemDefination=execute1")
execute2
    ItemListData(1)=(ItemDefination=execute2")

Note that you have an infinite loop. To not have an infinite loop, you could change the loop condition to something like while e < x to make the loop contents execute x times.

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