Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 91 additions & 0 deletions currency-converter-project.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# # Python Project on Currency Converter

import requests
from tkinter import *
import tkinter as tk
from tkinter import ttk


class RealTimeCurrencyConverter():
def __init__(self,url):
self.data = requests.get(url).json()
self.currencies = self.data['rates']

def convert(self, from_currency, to_currency, amount):
initial_amount = amount
if from_currency != 'USD' :
amount = amount / self.currencies[from_currency]

# limiting the precision to 4 decimal places
amount = round(amount * self.currencies[to_currency], 4)
return amount

class App(tk.Tk):

def __init__(self, converter):
tk.Tk.__init__(self)
self.title = 'Currency Converter'
self.currency_converter = converter

#self.configure(background = 'blue')
self.geometry("500x200")

# Label
self.intro_label = Label(self, text = 'Welcome to Real Time Currency Convertor', fg = 'blue', relief = tk.RAISED, borderwidth = 3)
self.intro_label.config(font = ('Courier',15,'bold'))

self.date_label = Label(self, text = f"1 Indian Rupee equals = {self.currency_converter.convert('INR','USD',1)} USD \n Date : {self.currency_converter.data['date']}", relief = tk.GROOVE, borderwidth = 5)

self.intro_label.place(x = 10 , y = 5)
self.date_label.place(x = 160, y= 50)

# Entry box
valid = (self.register(self.restrictNumberOnly), '%d', '%P')
self.amount_field = Entry(self,bd = 3, relief = tk.RIDGE, justify = tk.CENTER,validate='key', validatecommand=valid)
self.converted_amount_field_label = Label(self, text = '', fg = 'black', bg = 'white', relief = tk.RIDGE, justify = tk.CENTER, width = 17, borderwidth = 3)

# dropdown
self.from_currency_variable = StringVar(self)
self.from_currency_variable.set("INR") # default value
self.to_currency_variable = StringVar(self)
self.to_currency_variable.set("USD") # default value

font = ("Courier", 12, "bold")
self.option_add('*TCombobox*Listbox.font', font)
self.from_currency_dropdown = ttk.Combobox(self, textvariable=self.from_currency_variable,values=list(self.currency_converter.currencies.keys()), font = font, state = 'readonly', width = 12, justify = tk.CENTER)
self.to_currency_dropdown = ttk.Combobox(self, textvariable=self.to_currency_variable,values=list(self.currency_converter.currencies.keys()), font = font, state = 'readonly', width = 12, justify = tk.CENTER)

# placing
self.from_currency_dropdown.place(x = 30, y= 120)
self.amount_field.place(x = 36, y = 150)
self.to_currency_dropdown.place(x = 340, y= 120)
#self.converted_amount_field.place(x = 346, y = 150)
self.converted_amount_field_label.place(x = 346, y = 150)

# Convert button
self.convert_button = Button(self, text = "Convert", fg = "black", command = self.perform)
self.convert_button.config(font=('Courier', 10, 'bold'))
self.convert_button.place(x = 225, y = 135)

def perform(self):
amount = float(self.amount_field.get())
from_curr = self.from_currency_variable.get()
to_curr = self.to_currency_variable.get()

converted_amount = self.currency_converter.convert(from_curr,to_curr,amount)
converted_amount = round(converted_amount, 2)

self.converted_amount_field_label.config(text = str(converted_amount))

def restrictNumberOnly(self, action, string):
regex = re.compile(r"[0-9,]*?(\.)?[0-9,]*$")
result = regex.match(string)
return (string == "" or (string.count('.') <= 1 and result is not None))

if __name__ == '__main__':
url = 'https://api.exchangerate-api.com/v4/latest/USD'
converter = RealTimeCurrencyConverter(url)

App(converter)
mainloop()

128 changes: 128 additions & 0 deletions matrix calculator.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
#include<iostream>
#include<conio.h>
using namespace std;

void setmatrix(int array[3][3])
{
cout<<"Enter Values:\n";
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
cout<<"("<<i<<","<<j<<")= ";
cin>>array[i][j];
}
}
}

void showmatrix(int array[3][3])
{
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{cout<<array[i][j]<<" ";}
cout<<endl;
}
}

void matrixaddition(int array1[3][3],int array2[3][3])
{
int tempvariable;

for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
tempvariable=array1[i][j]+array2[i][j];
cout<<tempvariable<<" ";
}
cout<<endl;
}
}
void matrixmultiplication(int array1[3][3],int array2[3][3])
{
int tempvariable;
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{ int sum=0;
for(int k=0;k<3;k++)
{
sum+=array1[i][k]*array2[k][j];
}
tempvariable=sum;
cout<<tempvariable<<" ";
}
cout<<endl;
}
}

void matrixsubtraction(int array1[3][3],int array2[3][3])
{
int tempvariable;
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
tempvariable=array1[i][j]-array1[i][j];
cout<<tempvariable<<" ";
}
cout<<endl;
}
}

void matrixdivision(int array1[3][3],int array2[3][3])
{
cout<<"\nCant perform Division in matrices\n";

}
int main()
{
char c,doagain=' ';
int A[3][3], B[3][3]; //Two matrices

cout<<"Enter first matrix: \n";
setmatrix(A);

cout<<"\nEnter 2nd matrix: \n";
setmatrix(B);

cout<<"The two matrices are: \n";
showmatrix(A);

cout<<endl<<endl;
showmatrix(B);

while(doagain!='n')
{

cout<<"\nWhich operation do you want to perform(+,-,*,/)? : ";
cin>>c;
switch(c)
{
case '*':
matrixmultiplication(A,B);
break;

case '+':
matrixaddition(A,B);
break;

case '-':
matrixsubtraction(A,B);
break;

case '/':
matrixdivision(A,B);
break;

default:
cout<<"Invalid operator!!!";

}
cout<<"\nDo u want to perform another operation again(y/n)? :";
cin>>doagain;
}


}
14 changes: 14 additions & 0 deletions time conversion.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{ int hours,secs,mins;
cout<<"Enter no of hours= ";
cin>>hours;
mins=hours*60;
cout<<"Mins in given hours= "<<mins<<endl;
secs=mins*60;
cout<<"Seconds in given hours= "<<secs<<endl;

getch();
}