Program to Create a Lap Timer

import time

starttime=time.time()

lasttime=starttime

lapnum=1

print("Press ENTER to count laps.\nPress CTRL+C to stop")

try:

while True:

input()

laptime=round((time.time() - lasttime), 2)

totaltime=round((time.time() - starttime), 2)

print("Lap No. "+str(lapnum))

print("Total Time: "+str(totaltime))

print("Lap Time: "+str(laptime))

print("*"*10)

lasttime=time.time()

lapnum+=1

except KeyboardInterrupt:

print("Done")


Program to find yesterday’s, today’s and tomorrow’s date

from datetime import datetime, timedelta

currentday = datetime.now()

yesterday = currentday - timedelta(1)

tomorrow = currentday + timedelta(1)

print("Yesterday = ", yesterday.strftime('%d-%m-%Y'))

print("Today = ", currentday.strftime('%d-%m-%Y'))

print("Tomorrow = ", tomorrow.strftime('%d-%m-%Y'))


Program to Print Matrix in Z form

arr = [[5, 6, 7, 8],

    [1, 2, 3, 4],

    [5, 6, 7, 8],

    [9, 8, 7, 5]]

a = len(arr[0])

i=0

for j in range(0, a-1):

print(arr[i][j], end =" ")

k = 1

for i in range(0, a):

for j in range(a, 0, -1):

if(j==a-k):

print(arr[i][j], end = " ")

break;

k+=1

i=a-1;

for j in range(0, a):

print(arr[i][j], end = " ")

gTTS (Google Text-to-Speech)

 gTTS (Google Text-to-Speech)

a Python library and CLI tool to interface with Google Translate text-to-speech API

Features

Customizable speech-specific sentence tokenizer that allows for unlimited lengths of text to be read, all while keeping proper intonation, abbreviations, decimals and more

Customizable text pre-processors which can, for example, provide pronunciation corrections

Installation   $ pip install gTTS

Example  $ gtts-cli 'hello' --output hello.mp3

More

Convert Text to Speech

from gtts import gTTS

import os

mytext = 'Welcome to Python for Engineers,A Complete solution for python programming'

language = 'en'

myobj = gTTS(text=mytext, lang=language, slow=False)

myobj.save('WelcomeMsg.mp3')


Word Guessing Game

import random

words = ['rainbow', 'computer', 'science', 'programming',

'python', 'mathematics', 'game', 'condition',

'reverse', 'return', 'board']


word = random.choice(words)

print("Guess the characters")

guesses = ' '

turns = 11

while turns > 0:

failed = 0

for char in word:


if char in guesses:

print(char)

else:

print("_")

failed += 1

if failed == 0:

print("You Win")

print("The word is: ", word)

break

guess = input("guess a character:")

guesses += guess


if guess not in word:

turns -= 1

print("Wrong")

print("You have", + turns, 'more guesses')

if turns == 0:

print("You Loose")