### Archive

Archive for December 17, 2019

## Python: My Fake Data Generator P-3

Learning : Python: Functions, Procedures and documentation
Subject: About fake data P-3: (Fake Time)

The third function of our Fake Data Generator will be the Time function, Fake Time is very easy to implement, all we need is call random function two times, one for minutes (0,60) and another for hours (0,12 or 0,23) based on the argument s (style).

Let’s start: First we need to Import random, the function def ftime() will take one integer argument (s) represent the time style.
If the s = 12 then the time format will be regular start from 1 and end at 12, the number will be generated randomly using random.randint, also we will select random.choice([‘ AM’,’ PM’]) to be added to the time and return it back.
If the s = 24 or nothing been passed then the time format will start from 0 to 23 (Military Time Format). Another random integer (0,60) to be generated as minutes.

```
'''
Fake Data Generator
Function for:  Fake Time
11/12/2019
'''

import random

def ftime(s = 24):

"""
###   Fake Time Generator   ###

This function will generate a fake time, the
function accept one int argument s.

If s = 12 function return Regular time format,
If s = 24 function return military time format
(the 24 format system).

If No argument passes then default time system
format will be 24 system (military time)

Argument: int : s, if No argument then default is 24.

Return: str : ftimes
"""

m = str(random.randint(0,60))
if (len(m)) == 1 :
m = '0' + str (m)

if s == 12 :
h = str(random.randint(1,12))
if (len(h)) == 1:
h = '0' + h
else :
h = str(random.randint(0,23))
if (len(h)) == 1:
h = '0' + h

ftimes = str(h) + ':' + str(m)
if s == 12 :
ftimes = ftimes + random.choice([' AM',' PM'])

return ftimes

# Testing the function.
for x in range (10):
print (ftime(12))

```

:: Fake Function List ::

 Function Name Description Color To return a random color code in RGB or Hex. Date To return a random date. Mobile To return a mobile number. Country To return a random country name. City To return a random City name. ID To return X random dig as ID. Time To return random time. Car’s Brand Foods

 Done Follow me on Twitter..