0

I know the title is not that clear, I'll provide some information on what are the inputs and what output is needed. My input will be test steps, which will be dictionaries

   example:
    {"Teststep1":{"id":1,"Type":"Step","Text":"Pre Condition 1"}}

Here the id is 1, So by using python i need to change it to 1.1, for the next step it will be 1.2, for 3rd step1.3 and so on.

    so the output will be
    {"id":1.1, "Type":"step","Text":"Pre Condition 1"}}
    {"id":1.2, "Type":"step","Text":"Post Condition 2"}}

and also I can have substeps, i.e. step inside a step.

    {
     "Teststep1":
                 {
                     "id":1,"Type":"Step","Text":"Pre Condition 1"
                     {
                        "id":1.1,"Type":"sub_Step","Text":"precondition substep"
                     }
                 }
     }

Explaining the above code ::: we have a Teststep "Teststep1" containing data in it. Inside the step data, we have sub-data i.e. substep consists of the id: 1.1

how can I convert 1 to 1.1, 1.2 dynamically using python?

Thanks in advance

prithvi
  • 49
  • 1
  • 5

1 Answers1

0

You could initialize the variable to 0, change it to 1 the first time you check it and add 0.1 everytime you check it after that:

n = 0
for i in range(5):
    n = 1 if n == 0 else round(float(n) + 0.1, 1)
    print(n)

> 1
> 1.1
> 1.2
> 1.3
> 1.4