Python Micro Project
Python Micro Project
Group of Institutions
(Polytechnic)
Topic Name
Certificate
This is to certify that Mr. Omkar Ravindra Sarak Roll No: 28
of Sixth Semester of Diploma Programming in Engineering
& Technology at 1515–NIT Polytechnic Pune, has completed
the Micro Project satisfactorily in Subject Python Programming
[22616] in the academic year 2024-2025 as per the MSBTE
prescribed curriculum of I Scheme.
Seal Of
Institue
Index..
2 Objectives (Cos)
7 Evaluation Sheet
Abstract
The Rock-Paper-Scissors game is a simple yet popular hand game
played worldwide. It is a two-player game where each player
simultaneously selects one of three possible choices—rock, paper, or
scissors. The rules governing the game are straightforward: rock
crushes scissors, scissors cut paper, and paper covers rock. The
objective is to determine a winner based on these predefined rules. This
project implements the game using Python, allowing a single user to
compete against the computer.
• Example of Interaction:
The user types:
o "Enter first number: 5"
o "Enter second number: 3"
o "Select operation: 1 (Addition)"
o The program shows: "5 + 3 = 8"
2 .Graphical User Interface (GUI) Calculator:
• This type of calculator is built with a graphical interface using a library like
tkinter in Python. It resembles a physical digital calculator with buttons for
numbers and operations.
• User Interaction: The user interacts with the calculator by clicking on
buttons (representing numbers, operators, and other functions).
• Display: It shows a digital display (often a text field or screen on the
window) where numbers and the results of operations are shown.
• Operations: Similar to a physical calculator, it supports operations like
addition, subtraction, multiplication, division, and may even support
scientific functions (e.g., square roots, trigonometric functions).
• Input Method: The user clicks on buttons for input, and the result is
displayed directly on the screen of the GUI.
Example of Interaction:
• The user clicks on buttons:
o "5", "+", "3", "="
o The display shows: "8"
1. Arithmetic Operations:
o The core function of any digital calculator is to perform basic
arithmetic operations like:
▪ Addition: Adding two numbers together.
▪ Subtraction: Finding the difference between two numbers.
▪ Multiplication: Multiplying two numbers.
▪ Division: Dividing one number by another (with checks for
division by zero).
2. User Interface:
o Text-based Calculator: The user interacts through the terminal or
command line, entering inputs via keyboard and seeing results in
text format.
o Graphical Calculator: The user interacts through a visual interface
with buttons for each number, operation, and result. It provides a
more intuitive and interactive experience.
3. Error Handling:
o The calculator should handle invalid inputs (such as dividing by
zero) and inform the user with an appropriate error message. For
example, if a user tries to divide a number by zero, the calculator
should show an error like "Cannot divide by zero" instead of
crashing.
o
4. Scientific/Advanced Functions (optional):
o A more advanced digital calculator can support scientific
calculations, such as:
▪ Square roots
▪ Exponents
▪ Trigonometric functions (e.g., sine, cosine, tangent)
▪ Logarithms
• How It Works:
• Input: The user provides input, either through typing (for text-based
calculators) or by pressing buttons (for GUI-based calculators).
• Processing: The calculator processes the input, performs the arithmetic
operation(s), and computes the result.
• Output: The result is then displayed back to the user. For a text-based
calculator, it would appear in the terminal. For a graphical calculator, the
result appears on the digital display of the calculator window.
def press(num):
entry_text.set(entry_text.get() + str(num))
def clear():
entry_text.set("")
def equal():
try:
result = str(eval(entry_text.get()))
entry_text.set(result)
except:
entry_text.set("Error")
entry_text = tk.StringVar()
entry = tk.Entry(window, textvariable=entry_text, font=('Arial', 20), bd=10, insertwidth=2, width=14,
borderwidth=4, justify='right')
entry.grid(row=0, column=0, columnspan=4)
# Button layout
buttons = [
('7', 1, 0), ('8', 1, 1), ('9', 1, 2), ('/', 1, 3),
('4', 2, 0), ('5', 2, 1), ('6', 2, 2), ('*', 2, 3),
('1', 3, 0), ('2', 3, 1), ('3', 3, 2), ('-', 3, 3),
('0', 4, 0), ('.', 4, 1), ('=', 4, 2), ('+', 4, 3),
('C', 5, 0)
]
Reference :
1.Python Official Documentation
• Python Docs: The official Python documentation is the best place to start
for learning about the basic language features, syntax, and modules that
you can use to create a calculator.
• Python Docs
• Tutorials: There are many beginner-friendly tutorials that teach you how
to build a GUI calculator using Tkinter.
Example: Python Tkinter Calculator Tutorial
• Tkinter Documentation:Tkinter Documentation