Voice Recorder using python

 install portaudio using:

               pip install portAudio

install portaudio library:
    
               sudo apt-get install libportaudio2


import sounddevice
from scipy.io.wavfile import write 
fs=44100 #sample_rate
second=int(input("Enter the time duration in second: "))
print("Recording....\n")
record_voice=sounddevice.rec(int(second * fs),samplerate=fs,channels=2)
sounddevice.wait()
write("out.wav",fs,record_voice)
print("Finished....\nPlease check it...")

Compound Interest GUI Calculator using Tkinter

# importing classes and functions from the tkinter

from tkinter import *

# Function for clearing the

# contents of all entry boxes

def clear_all() :

# whole content of entry boxes is deleted

principle_field.delete(0, END)

rate_field.delete(0, END)

time_field.delete(0, END)

compound_field.delete(0, END)

# set focus on the principle_field entry box

principle_field.focus_set()

# Function to find compound interest

def calculate_ci():

# get a content from entry box

principle = int(principle_field.get())

rate = float(rate_field.get())

time = int(time_field.get())

# Calculates compound interest

CI = principle * (pow((1 + rate / 100), time))

# insert method inserting the

# value in the text entry box.

compound_field.insert(10, CI)

#code

if __name__ == "__main__" :

# Create a GUI window

root = Tk()

# Set the background colour of GUI window

root.configure(background = 'white')

# Set the configuration of GUI window

root.geometry("400x250")

# set the name of tkinter GUI window

root.title("Compound Interest Calculator")

# Create a Principle Amount : label

label1 = Label(root, text = "Principle Amount(Rs) : ",

fg = 'white', bg = 'black')

# Create a Rate : label

label2 = Label(root, text = "Rate(%) : ",

fg = 'white', bg = 'black')

# Create a Time : label

label3 = Label(root, text = "Time(years) : ",

fg = 'white', bg = 'black')


# Create a Compound Interest : label

label4 = Label(root, text = "Compound Interest : ",

fg = 'white', bg = 'black')

# grid method is used for placing

# the widgets at respective positions

# in table like structure .

# padx keyword argument used to set padding along x-axis .

# pady keyword argument used to set padding along y-axis .

label1.grid(row = 1, column = 0, padx = 10, pady = 10)

label2.grid(row = 2, column = 0, padx = 10, pady = 10)

label3.grid(row = 3, column = 0, padx = 10, pady = 10)

label4.grid(row = 5, column = 0, padx = 10, pady = 10)

# Create a entry box

# for filling or typing the information.

principle_field = Entry(root)

rate_field = Entry(root)

time_field = Entry(root)

compound_field = Entry(root)

# grid method is used for placing

# the widgets at respective positions

# in table like structure .

# padx keyword argument used to set padding along x-axis .

# pady keyword argument used to set padding along y-axis .

principle_field.grid(row = 1, column = 1, padx = 10, pady = 10)

rate_field.grid(row = 2, column = 1, padx = 10, pady = 10)

time_field.grid(row = 3, column = 1, padx = 10, pady = 10)

compound_field.grid(row = 5, column = 1, padx = 10, pady = 10)

# Create a Submit Button and attached

# to calculate_ci function

button1 = Button(root, text = "Submit", bg = "red",

fg = "black", command = calculate_ci)

# Create a Clear Button and attached

# to clear_all function

button2 = Button(root, text = "Clear", bg = "red",

fg = "black", command = clear_all)

button1.grid(row = 4, column = 1, pady = 10)

button2.grid(row = 6, column = 1, pady = 10)

# Start the GUI

root.mainloop()


Number guessing game (Basic Python Project)

import random

import math

# Taking Inputs

lower_input = int(input("Enter lower_input number:- "))

# Taking Inputs

upper_input = int(input("Enter upper_input number:- "))

# generating random number between

# the lower_input and upper_input

x = random.randint(lower_input, upper_input)

print("\n\tYou've only ",

round(math.log(upper_input - lower_input + 1, 2)),

" chances to guess the integer!\n")

# Initializing the number of guesses.

count = 0

# for calculation of minimum number of

# guesses depends upon range

while count < math.log(upper_input - lower_input + 1, 2):

count += 1

# taking guessing number as input

guess = int(input("Guess a number:- "))

# Condition testing

if x == guess:

print("Congratulations you did it in ",

count, " try")

# Once guessed, loop will break

break

elif x > guess:

print("You guessed too small!")

elif x < guess:

print("You Guessed too high!")

# If Guessing is more than required guesses,

# shows this output.

if count >= math.log(upper_input - lower_input + 1, 2):

print("\nThe number is %d" % x)

print("\tBetter Luck Next time!")


Sorted Linked List to Balanced Binary search tree

class LNode :

def __init__(self):

self.data = None

self.next = None

class TNode :

def __init__(self):

self.data = None

self.left = None

self.right = None

head = None

def sortedListToBST():

global head

n = countLNodes(head)

return sortedListToBSTRecur(n)

def sortedListToBSTRecur( n) :

global head

if (n <= 0) :

return None

left = sortedListToBSTRecur( int(n/2))

root = newNode((head).data)

root.left = left

head = (head).next

root.right = sortedListToBSTRecur( n - int(n/2) - 1)

return root

def countLNodes(head) :

count = 0

temp = head

while(temp != None):

temp = temp.next

count = count + 1

return count

def push(head, new_data) :

new_node = LNode()

new_node.data = new_data

new_node.next = (head)

(head) = new_node

return head

def printList(node):

while(node != None):

print( node.data ,end= " ")

node = node.next

def newNode(data) :

node = TNode()

node.data = data

node.left = None

node.right = None

return node

def preOrder( node) :

if (node == None) :

return

print(node.data, end = " " )

preOrder(node.left)

preOrder(node.right)

head = None

head = push(head, 7)

head = push(head, 6)

head = push(head, 5)

head = push(head, 4)

head = push(head, 3)

head = push(head, 2)

head = push(head, 1)

print("Given Linked List " )

printList(head)

root = sortedListToBST()

print("\nPreOrder Traversal of constructed BST ")

preOrder(root)

Python Logo Using Turtle in Python

import turtle

turtle_cursor = turtle.Turtle()

turtle_screen = turtle.Screen()

def pause():

    turtle_cursor.speed(2)

    for i in range(100):

        turtle_cursor.left(90)

def upper_dot_of_python_logo():

    turtle_cursor.penup()

    turtle_cursor.right(90)

    turtle_cursor.forward(160)

    turtle_cursor.left(90)

    turtle_cursor.forward(70)

    turtle_cursor.pencolor("white")

    turtle_cursor.dot(35)

def second_position():

    turtle_cursor.penup()

    turtle_cursor.forward(20)

    turtle_cursor.right(90)

    turtle_cursor.forward(10)

    turtle_cursor.right(90)

    turtle_cursor.pendown()

def half():

    turtle_cursor.forward(50)

    draw_side_curve_of_python_logo()

    turtle_cursor.forward(90)

    draw_first_left_curve_of_python_logo()

    turtle_cursor.forward(40)

    turtle_cursor.left(90)

    turtle_cursor.forward(80)

    turtle_cursor.right(90)

    turtle_cursor.forward(10)

    turtle_cursor.right(90)

    turtle_cursor.forward(120)  

    draw_second_left_curve_of_python_logo()

    turtle_cursor.forward(30)

    turtle_cursor.left(90)

    turtle_cursor.forward(50)

    draw_right_curve_of_python_logo()

    turtle_cursor.forward(40)

    turtle_cursor.end_fill()

def lower_dot_of_python_logo():

    turtle_cursor.left(90)

    turtle_cursor.penup()

    turtle_cursor.forward(310)

    turtle_cursor.left(90)

    turtle_cursor.forward(120)

    turtle_cursor.pendown()

    turtle_cursor.dot(35)

def draw_first_left_curve_of_python_logo():

    draw_side_curve_of_python_logo()

    turtle_cursor.forward(80)

    draw_side_curve_of_python_logo()

def draw_second_left_curve_of_python_logo():

    draw_side_curve_of_python_logo()

    turtle_cursor.forward(90)

    draw_side_curve_of_python_logo()

def draw_side_curve_of_python_logo():

    for i in range(90):

        turtle_cursor.left(1)

        turtle_cursor.forward(1)

def draw_right_curve_of_python_logo():

    for i in range(90):

        turtle_cursor.right(1)

        turtle_cursor.forward(1)

turtle_cursor.pensize(2)

turtle_cursor.speed(10)

turtle_cursor.pensize(2)

turtle_cursor.pencolor("black")

turtle_screen.bgcolor("white")

turtle_cursor.fillcolor("#306998")

turtle_cursor.begin_fill()

half()

turtle_cursor.end_fill()

second_position()

turtle_cursor.fillcolor("#FFD43B")

turtle_cursor.begin_fill()

half()

turtle_cursor.end_fill()

upper_dot_of_python_logo()

lower_dot_of_python_logo()

pause