IP Project in Python Unit Calculator
IP Project in Python Unit Calculator
IP Project in Python Unit Calculator
AISSCE Examination-2020
Informatics Practices project
On
Unit Converter
Guided by-Mr. Kundan Kamal
Name : Aman Kumar Mahato
Roll No:
Exam : AISSCE
Date -
Internal Examiner
Basic operation is simple: you enter the units that you want to
convert from and the units that you want to convert to. You can use
the program interactively with prompts, or you can use it from the
command line.
You can change the default behavior of units with various options
given on the command line. See Invoking Units, for a description of
the available options.
Python is a widely used general-purpose, high level programming
language. It was initially designed by Guido van Rossum in 1991 and
developed by Python Software Foundation. It was mainly developed
for emphasis on code readability, and its syntax allows programmers to
express concepts in fewer lines of code.
Python is a programming language that lets you work quickly and
integrate systems more efficiently.
2) Expressive Language
Python language is more expressive means that it is more
understandable and readable.
3) Interpreted Language
Python is an interpreted language i.e. interpreter executes the
code line by line at a time. This makes debugging easy and
thus suitable for beginners.
4) Cross-platform Language
Python can run equally on different platforms such as
Windows, Linux, Unix and Macintosh etc. So, we can say that
Python is a portable language.
6) Object-Oriented Language
Python supports object oriented language and concepts of
classes and objects come into existence.
7) Extensible
It implies that other languages such as C/C++ can be used to
compile the code and thus it can be used further in our python
code.
10) Integrated
It can be easily integrated with languages like C, C++, JAVA
etc.
Several books provide conversion factors and algorithms for use in unit
conversion. The available books differ widely in the number of units
covered, the accuracy of the conversion factors, and the algorithms
that some books present for unit conversion. Although one might think
that unit conversion is easy and ``everyone knows how to do it'', the
number of books and the variety of methodologies and algorithms they
present suggest otherwise.
Unit conversion is a multi-step process that involves multiplication or
division by a numerical factor, selection of the correct number of
significant digits, and rounding. This multi-step process is presented
in NIST SP 1038 - 2006 (Section 4.4), including a rounding procedure for
technical documents, specifications, and other applications such
packaged goods in the commercial marketplace and temperature.
Import tkinter as tk
root = tk.Tk()
root.title(('UNIT CONVERTER'))
controls = []
cboxindices = []
def onkeypress(event):
st = event.widget.get()
ch = event.char
ic = event.widget.index(tk.INSERT)
if ch == deletechar:
st = st[:ic-1] + st[ic:]
else:
st = st[:ic] + ch + st[ic:]
def onselection(event):
unittypeindex = icunittype
if controlindex == unittypeindex:
setupcomboboxes(1)
process(controlindex)
def setupcomboboxes(mode):
unittypeindex = icunittype
if mode == 0:
units = []
units.append(item[0])
controls[unittypeindex]['values'] = units
unittype = controls[unittypeindex].current()
convs = conversiondata[unittype][1].conversions
units = []
for u in convs:
units.append(u[0])
cur = 0
controls[cindex]['values'] = units
controls[cindex].current(cur)
cur += 1
oldvalue = 1.0
# convert the current entry value from old to the new units
conv = conversiondata[unittype][1].conversions
- conv[newunit][2])/ conv[newunit][1]
newvaluetext = '{:.5}'.format(newvalue)
newvaluetext = '{:.5e}'.format(newvalue)
controls[icnewvalue].configure(text=newvaluetext)
return newvalue
noend = '+-Ee'
noreps = '.Ee'
global oldvalue
pm = '+-'
stl = len(st)
if type == 0:
ic = 0
for c in st:
if not valid:
type = -1
break
if norep:
type = -1
break
ic = ic + 1
if type == 0:
ch = st[-1]
if ch == '+' or ch == '-':
if type == 0:
if st[-1] not in noend:
# st[-1] is the last element, [-2] the one preceding it, ...
type = 1
else:
if endflag != 0: type = -1
return type
global oldvalue
oldvalue = controls[icoldvalue].get()
if controlindex == icoldvalue:
if flag < 0:
col = 'red'
controls[icoldvalue].configure(bg=col)
if flag <= 0:
return
unittype =controls[icunittype].current()
oldunit = controls[icoldunit].current()
newunit = controls[icnewunit].current()
# Do the conversion
newvalue = convert(unittype, oldvalue, oldunit, newunit)
class Length:
conversions = (('cms', 1.0, 0.), ('meters', 1.0e2, 0.), ('kilometers', 1.0e5, 0.),
class Mass:
class Temperature:
('Temperature', Temperature()))
for c in controldata:
if c[1] == 'Combobox':
if c[1] == 'Entry':
control.bind('<Key>', onkeypress)
if c[1] == 'Label':
w = 12
col = 'lightgreen'
t=' '
col = 'red'
t = '='
controls.append(control)
process()
root.mainloop()
“Program Ends”
Unit conversion is a problem that will not go away, even if the United
States converts to the SI system. Workers in particular fields will
continue to use units such as parsec or micron rather than meter, both
because of tradition and because such units are convenient in size for
the measurements typically used in practice. The compiler algorithms
that we have described are relatively easy to implement, so that units
could be incorporated into a variety of programming languages. These
algorithms make it feasible to implement essentially all known units of
measurement, so that users may use any units they find convenient.
Informatics Practices(Sumita Arora, DHANPAT RAI &CO)
www.projectworlds.in
www.w3resource.com
www.daniweb.com
www.codereview.stackexchange.com