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
10 changes: 0 additions & 10 deletions Problem Statement 1/README.md

This file was deleted.

10 changes: 0 additions & 10 deletions Problem Statement 2/README.md

This file was deleted.

23 changes: 23 additions & 0 deletions Problem Statement 3/README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,32 @@
Link for task submission video
TASK 3 CALCULATOR Using Python :
**https://youtu.be/1OeMWxhRSOA**


# Problem Statement-3.


***
### Make a calculator with GUI

Hello
I’m Chetan Chinchulkar from IITG

This video is regarding problem statement 3 under GameOfCodes. GameOfCodes Python is a coding competition based on Python problem statements.
Problem statement 3 is Calculator with GUI using Python

There are two versions of the calculator :
Standard calculator
Bsic mathemcatival operations are available
Scientific calculator
Advanced mathematical operations like trigometric functions,exponential etc are added

In addition to this, it has Rand button to randomly generate and show any random number. This also has Signum function.

Error Handling
The GUI takes care of varies error by correspondingly displaying error messages.

Uniqueness of this calculator is copying the result, and also has age calculator


***
Expand Down
Binary file not shown.
Binary file added Problem Statement 3/age.ico
Binary file not shown.
104 changes: 104 additions & 0 deletions Problem Statement 3/age_calculator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# importing modules
from email import message
from tkinter import *
from datetime import date,datetime
from tkinter import messagebox


root = Tk() # creating window
root.title("AGE-CALCULATOR") # setting up title
root.configure(bg="#fff") # setting up background color
root.geometry("400x300") # fixing the size of the window
root.iconbitmap("age.ico") # set Icon
new = Label(root, bg="#fff") # declaring a label
new.grid(row=5, column=0, columnspan=3)

today = str(date.today()) # getting current date using datetime module
list_today = today.split("-") # converting into a list


# defining a function to calculate age
def age(b_date, b_month, b_year):
try:
global today
global new


date_string = entry_year.get()+'-'+entry_month.get()+'-'+entry_date.get()
birthdate = datetime.strptime(date_string, '%Y-%m-%d').date()

if birthdate>date.today():
messagebox.showwarning("WARNING", "You are not born yet \n Enter correct date")
else:
new.grid_forget()
b_date = int(entry_date.get())
b_month = int(entry_month.get())
b_year = int(entry_year.get())
c_date = int(list_today[2])
c_month = int(list_today[1])
c_year = int(list_today[0])
month = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
if b_date > c_date:
c_month = c_month-1
c_date = c_date+month[b_month-1]
if b_month > c_month:
c_year = c_year-1
c_month = c_month+12
resultd = str(c_date-b_date)
resultm = str(c_month-b_month)
resulty = str(c_year-b_year)
new = Label(root, text="YOUR AGE \n"+resulty+" YEARS "+resultm+" MONTHS " +
resultd+" DAYS ", fg="#000", bg="#D5C6FF", borderwidth=6)
new.config(font=("Arial Rounded MT Bold", 15))
new.grid(row=5, column=0, columnspan=3)
except Exception as err:
messagebox.showerror("Error", "Please enter a valid date \n Error : "+str(err))


# defining a function to clear the previous entries
def clean(entry_date, entry_month, entry_year):
global new
new.grid_forget()
entry_date.delete(0, END)
entry_month.delete(0, END)
entry_year.delete(0, END)


# creating widgets such as labels,entry boxes and buttons and fixing its position onto window
title_label = Label(root, text="AGE CALCULATOR", borderwidth=10, fg="#404042", bg="#fff")
title_label.config(font=("Arial Rounded MT Bold", 29))
title_label.grid(row=0, column=0, columnspan=3)
label_date = Label(root, text="BIRTH DATE : ", borderwidth=4, fg="#404042", bg="#fff")
label_date.config(font=("Arial Rounded MT Bold", 15))
label_date.grid(row=1, column=0)
label_month = Label(root, text="BIRTH MONTH : ", borderwidth=5, fg="#404042", bg="#fff")
label_month.config(font=("Arial Rounded MT Bold", 15))
label_month.grid(row=2, column=0)
label_year = Label(root, text="BIRTH YEAR : ", borderwidth=9, fg="#404042", bg="#fff")
label_year.config(font=("Arial Rounded MT Bold", 15))
label_year.grid(row=3, column=0)

entry_date = Entry(root, width=20, borderwidth=3)
entry_month = Entry(root, width=20, borderwidth=3)
entry_year = Entry(root, width=20, borderwidth=3)

entry_date.grid(row=1, column=2)
entry_month.grid(row=2, column=2)
entry_year.grid(row=3, column=2)

# getting the value in the entry boxes
b_date = entry_date.get()
b_month = entry_month.get()
b_year = entry_year.get()

# calling age function in button widget
submit = Button(root, text="GET AGE!!", width=10, anchor=CENTER, command=lambda: age(b_date, b_month, b_year),
fg="black" )
submit.grid(row=4, column=0)

# calling clean function in button widget
clear = Button(root, text="CLEAR", width=10, command=lambda: clean(entry_date, entry_month, entry_year),
fg="black")
clear.grid(row=4, column=2)

root.mainloop()
Binary file added Problem Statement 3/images/logo1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Problem Statement 3/images/logo2.ico
Binary file not shown.
Binary file added Problem Statement 3/images/logo2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading