Question: I have a financial system and I have to design a module for save, update and control limitation. 
You can know each customer has a UserID and each UserID has a maximum amount of credit per day. For example, **UserID = 12 has MaxAmountPerDay = 10$** and **CurrentAmountPerDay**.

At first, I wanted to design a simple module and define a table as follows:

```
  User ID | MaxAmountPerDay | CurrentAmountPerDay
-------------------------------------------------
  12     | 10              | 0
  25     | 100             | 84

```

Now you can imagine when the customer with **UserID = 12** has done a transaction I have to control if the **transaction amount + current amount > max amount** then throw an exception else I have to do the transaction and update current amount and when an exception happened after updating I have to rollback the update operation.(update and rollback are in different database transactions so the rollback is the same update with new amount)

Before I do this design I decided to look up for a better solution or even an open source framework for doing that because I guess my customer's requirements will change in future, for example maybe they will need to **MaxAmountPerMonth**, or some more requirements which I don't know now.

Answer: 
We can create a `function` that takes a `string` and `returns` the `time`.

This can all be done in one line by `slicing` the `string` up to the `minutes` (done with `[:2]`) and then concatenating a `':'` and finally concatenating the `minutes` with `[2:]`.

```
def getTime(t):
    return t[:2] + ':' + t[2:]

```

and some tests to show it works:

```
>>> getTime("1230")
'12:30'
>>> getTime("0730")
'07:30'
>>> getTime("1512")
'15:12'

```

---

Note how the `function` *cannot* take an `integer` and convert this to a `string`, as otherwise entries with leading zeros would fail. E.g. `0730` wouldn't work.

---

Yes, to answer `@AbhishtaGatya`, this could be written using a `lambda` function, but doing so wouldn't be advisable. However:

```
getTime = lambda t: t[:2] + ':' + t[2:]

```

works just the same as above.
You can insert ":" to the index 2

```
val = 1230
new= ([str(i) for i in str(val)])
new.insert(2,":")

print(''.join(new))

```

**output:**

```
12:30

```