Tuesday, March 30, 2021

Typing speed calculator program in python [ 15 lines ]

 

Hello python programmers, This is AK in this blog we’re going to learn about how to create your

 own typing speed tester program using python. Before starting this program you must have a 

strong basics knowledge of python programming. So this program is a super simple one and

 it produces more accurate results.

 

For this program, you don’t need to install any python packages. I'm using the built-in packages

 to create this program. So don’t worry about the package installations.

 

 



 

 

Step 1 :

For checking the typing speed of yours, you’ve to type some words to generate your results. 

For that process create a variable called a string and in this variable, you’ve to type some sentences.


import time
String='subscribe to Akpython'

 

Why we are creating this variable means. For checking your typing speed you need to type some

 sentences. According to that typing performances, the results are generated. So this our process. 

And you need to type this sentence in the output to check your typing accuracy, wpm and time taken 


Step 2:

Next, create a variable called word count and in this variable, you need to print the length of the 

sentence that you’re going to type.

 

wordcount=len(String.split())
print(String) 

 

Previously we declared a string as a sentence For counting each word on the sentence you

 need to split the variable string. In python, There is one useful method is split(). Using this split we

 can easily split the string into list form. Using the length method we can easily find out the length of

 each string after splitting the sentence. 

 

Step 3:

 

while True:
t0=time.time()
inputtext=str(input('Enter the Sentence:'))
t1=time.time()
 

 

So next step we need to create a loop and in this loop, we’re going to calculate the time taken to

 type the sentence. After that, you need to create an input text when you run this script you’re going to

 type the entire sentence in this variable. When you’re typing the sentence this program analysis your

 all typing speed, accuracy, words per minute to type the sentence.


These are the parameters we’re going to calculate under this while loop, First, we’re going to calculate

 the typing speed, For calculating the typing speed you need to find the difference between starting time

 & ending time of your typing.

 

Create a variable called  t0 and pass the object time.time() and So this variable used to record the 

starting time and next you’ve to create another variable called t1. Consider this variable as ending time. 

When subtracting these two-variable timings we get the time taken to type the entire word  

 

Step 4:

Next, create a variable called accuracy we are going to find out the accuracy of our typing.

 Suppose when you are missing some words in the actual sentences then your accuracy rank

 will get low.


 
accuracy=len(set(inputtext.split())&set(String.split()))
accuracy=accuracy/wordcount

So in this variable, you need to use the set method to find out the uniqueness in both sentences. 

So we’re calling the set of input text that we’re going to type and also we’re calling another set that

 is a set of the actual string.

If you miss any words in the input text variable your length of the word is going to decrease.

 When your length of the sentence that decreases your accuracy also decreases. So this is a concept

 I think you will understand this step.

 

And in this accuracy variable you need to make the formula as accuracy divided by word count

 this is the formula to find out the accuracy of your typing

 

Step 5:

timetaken=t1-t0

wpm=wordcount/timetaken

print("WPM",wpm,"Accuracy",accuracy,"Timetaken",timetaken) 

So in the case of words per minute, we’re having some formula that is word_count  is divided by the

 time taken.


So this formula is used to produces the wpm result of your typing.


And finally, print the statement, and let’s run this program



Full code : Typing speed calculator

 

Thanks for reading👍





Thursday, March 25, 2021

Realtime QRcode scanner using python [ 30 lines ]

 Hello python programmers, This is AK, In this blog we're going to learn about how to create a QR code scanner using python programming.

Now a days Qr code is a much needed one for doing transactions, sharing links and encrypt the data like that.

So in this blog we're going to create a python program that is used to scan any type of QR code and it redirects you to the link that hidden in the Qr code.

 In the many tutorials about Qr code scanner using python. They're scanning the picture of Qr code and it redirects you to link that behind in the Qr code.

In this blog,We're not doing like that but we're going to capture the qr code by real time through the webcam of my PC.

Before starting this blog, You need to know about how this process is going to work,Firstly you need to open your webcam and you've to run your python program make it ready to scan the qr code.

You can take Qr code picture on your mobile and show the picture in front of your webcam.

It correctly identifies the qr code that present in your screen.And this program redirects you to link that hidden in the qr code.

So this is the process of how this program works.

Before start to create this program do like ,share, comment and subscribe these things will motivate me to produce more good contents in python programming.

 Let's start this video.

1.Creating the Qr code

First you need to create a qr code for performing the QR scanning script. You can take any Qr code.But in this video I want to show you how to create a qr code by using python.


For creating the qr code you need to install a python package. We all know how to install a python package in command prompt


Command: pip install pyqrcode

Command: pip install pypng ( Saves the qr code image in png format ) 

 

First import the pyqrcode and png library, From the pyqrcode you've to import the Qr code function.

 

import pyqrcode
import png
from pyqrcode import QRCode

And then create a variable called as link and in this variable you need to insert the link that you want to hide behind the qr code.

 

link = "www.example.com" 


So next call the instance pyqrcode.create and inside this object pass the parameter link.And the next step you need to mention the format of image that you want to save the qr code.


url = pyqrcode.create(link)
url.png('myqr.png', scale = 6)

Output after running this script.


2.Creating the Qr code scanner

For creating the Qr code scanner you've to install the OpenCv library in your terminal

Command: pip install opencv-python

Step:1 

First you need to import the opencv and webrowser library in your IDE.

 import cv2
import webbrowser

 

Step:2 

 Next we need to start the camera for the capturing the qr code .For that declare a variable called as cap and in this variable pass the instance cv2.VideoCapture(0).

Next process is we need to create a variable called detector and in this variable call the object cv2.QRCodeDetector(). 

 

cap = cv2.VideoCapture(0)
detector = cv2.QRCodeDetector() 

 

Step:3 

This step is very important you need to create a while loop and in this loop create a variable called a img and this will read your webcam screen continuously until this loop breaks

 while True:
    _, img = cap.read()


Step:4

Next create a variable called as data and this variable to used decode the qr code and if any data present in the qr code image it will break the loop and it opens the link in your browser. So this is the condition that I inserted here.

data, _ = detector.detectAndDecode(img)
    if data:
        a=data
        break
    cv2.imshow("QRCODEscanner", img)    
    if cv2.waitKey(1) == ord("q"):
        break

b=webbrowser.open(str(a))
cap.release()
cv2.destroyAllWindows()


 

Full code: Qrcode scanner code

Thanks for reading 💗

Wednesday, March 24, 2021

Secure OTP generator using python

 

Hello python programmers this is ak, In this blog, we are going to create an algorithm that generates OTP. You can see OTP is a very important one for doing online transactions, account signup process.

 

 

 


 


It is considered a very highly secured algorithm nowadays it is used to reduce account compromising and it can protect our account credentials from hackers.


One who gets your mobile OTP password can do anything on your accounts. So only it is a very secure one and its time is valid for only a short span of time.

 

In this blog, we are going to create a simple algorithm that helps to log in by using a one-time password. This article is very helpful for beginners who are learning python. And this helps you to understand how to solve programming problems in interviews. So watch this video fully to understand the entire concept.

 

First, we need to understand how this process is going to work in our IDE. Firstly we’ve to set the numbers from any range. Using the numbers range we are going to generate a one-time password.


 

First, we are going to randomize the numbers for generating random numbers. So when we run the program every time this program generates random different numbers from a range that we are going to give.


First import the random module, This library is a built-in library and you don’t need to install this on your terminal. And create a variable called generatorotp, using this variable we’re going to randomize the numbers range. So in the variable, you’ve to type random.randint( and inside this object, you need to pass the number range, you can give any numbers that you want). So here I give the number as six zeros as starting range and ending range is 100000. 

 

Step1: import random & set the range

 

 import random
gen=random.randint(000000,100000) 

 

 

So this program used to generate the numbers from this range.

 

Step2: Create username for login


And next one is you need to create a variable called username this variable is used to take the username that you have given in the program.

 

username=input('Enter the username:')
print('hello',username)
print('Here is your OTP:',gen)

 

Step3: Create password variable for login process

 

password=input("Enter the otp to login:") 

 

So after this step creates a variable called password in this variable we’re going to give the OTP for the login process.

 

 Step4: Create a condition

 

 if password==str(gen):
print('Login success')
else:
password!=str(gen)
print('login failed')

 

 

And the next step is you need to create a condition. The first condition explains that if the password is equal to the OTP it will print login success.

Another condition is if it is not equal to OTP it will print login failed.

 

 

Full code : OTP login using python 

 

 

 

Thanks for reading💗