Professional Documents
Culture Documents
Python mc removed
A MICRO-PROJECT REPORT ON
“MATH GAME”
For The Award Of
DIPLOMA IN COMPUTER ENGINEERING & TECHNOLOGY
(COMPUTER ENGINEERING)
2022-23
UNDER THE GUIDANCE OF
Prof.A.V.WANKAR
SUBMITTED BY
SR NAME ENROLLMENT NO
CERTIFICATE
GOVERNMENT POLYTECHNIC, AMBAD.1162
This is to certify that the Micro-project entitled “Math Game being submitted
herewith for the award of
DIPLOMA IN ENGINEERING & TECHNOLOGY in COMPUTER
ENGINEERING of MAHARASHTRA STATE BOARD &TECHNICAL
EDUCATION (MSBTE), Mumbai is the result of Micro-project work completed
under my supervision and guidance by Prof.A.V.Wankar
Mr.
To the best of my knowledge and belief, the work embodied in this Microproject
has not formed earlier the basis for the award of any diploma of this or any other Board
or examining body.
DECLARATION
We, the undesired, hereby declare that the project entitled “Math
Game” Is written and submitted by us to GovernmentPolytechnic
Ambad during Year 2022-23, Six Semester for partial
fulfillment of the ‘Micro Project’ requirement of "Programming With
Python" subject under Maharashtra State Board of Technical
Education, Mumbai curriculum, under the guidance of Prof.A.V.WANKAR. is
our original work.
The empirical findings in this project are based on the data collected in this
project is collected from various sources.
ACKNOWLEDGEMENT
I have great pleasure to express my immense gratitude towards a dynamic person and
my project guide Prof.A.V.WANKAR
I am indeed indebted to my parents and other family members for their immense
help at all levels with moral, social & financial support, care and support throughout
my studies without which my work would not have seen light of the day.
Date:---/---/--- Mr./Miss.----------
Index
01 Introduction
02 Module Needed
03 Function Need
04 Code
05 Output
• This code is a simple math game that generates random math problems and asks
the user to solve them. The game keeps track of the user's score and ends when
the user decides to stop playing.
❖ MODULE NEEDED
• There are two modules used in this python code random and operator.
❖ FUNCTION NEEDED
The random_problem() : function generates two random numbers between 1 and 10,
selects a random math operator from a dictionary of operators, performs the math
operation using the operator module, and returns the answer.
The game() : function initializes the user's score to 0 and enters a loop that continues
until the user decides to stop playing.
In each iteration of the loop, it calls ask_question() to ask the user a math problem and
updates the user's score if the user's guess was correct. If the user's guess was incorrect,
the loop breaks and the game ends. Finally, the user's score is displayed.
❖ PROGRAM
import random
import operator
def random_problem():
operators = {
'+': operator.add,
'-': operator.sub,
'*': operator.mul,
'/': operator.truediv,
}
def ask_question():
answer = random_problem()
guess = float(input('Enter you answer: '))
return guess == answer
def game():
score = 0
while True:
if ask_question() == True:
score += 1
print('Correct !')
else:
print('Incorrect')
break
print(f'======== Game Over ========\nYou score is {score}\nKepp going!')
game()
❖ OUTPUT
❖ CONCLUSION :
The random_problem() function can generate division by zero errors if the randomly
generated operator is / and the second number is 0.
The ask_question() function assumes that the user will enter a float as their guess, but
it does not handle cases where the user enters a non-numeric value.
The game() function does not handle cases where the user enters a non-numeric value
as their guess.