Commit 51082e4c authored by vipul.v's avatar vipul.v

first comit

parent 91096075
# Default ignored files
/shelf/
/workspace.xml
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/venv" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.11 (calculatorpy)" project-jdk-type="Python SDK" />
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/calculatorpy.iml" filepath="$PROJECT_DIR$/.idea/calculatorpy.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/calculator-python-code" vcs="Git" />
</component>
</project>
\ No newline at end of file
# Calculator Python code
In this project we can Add, Subtract, Multiply and Divide. Have used OOPS concepts and functions.
\ No newline at end of file
class calculator:
def sum(self, x, y):
return x + y
def difference(self, x, y):
return x - y
def multiplication(self, x, y):
return x * y
def division(self, x, y):
return x / y
my_function = calculator()
while True:
print()
print("CHOICE 1: SUM")
print("CHOICE 2: DIFFERENCE")
print("CHOICE 3: MULTIPLICATION")
print("CHOICE 4: DIVISION")
print("CHOICE 5: EXIT")
print()
choice = int(input("Enter a choice: "))
print()
if choice not in [1, 2, 3, 4, 5]:
print("Please, enter a valid Input")
elif choice == 5:
break
else:
x = int(input("Enter first number: "))
y = int(input("Enter second number: "))
if (choice == 1):
print("RESULT -->", x, "+", y, "=", my_function.sum(x, y))
elif (choice == 2):
print("RESULT -->", x, "-", y, "=", my_function.subtraction(x, y))
elif (choice == 3):
print("RESULT -->", x, "*", y, "=", my_function.multiplication(x, y))
elif (choice == 4):
print("RESULT -->", x, "/", y, "=", my_function.division(x, y))
\ No newline at end of file
class calculator:
def sum(self, x, y):
return x + y
def difference(self, x, y):
return x - y
def multiplication(self, x, y):
return x * y
def division(self, x, y):
return x / y
my_function = calculator()
while True:
print()
print("CHOICE 1: SUM")
print("CHOICE 2: DIFFERENCE")
print("CHOICE 3: MULTIPLICATION")
print("CHOICE 4: DIVISION")
print("CHOICE 5: EXIT")
print()
choice = int(input("Enter a choice: "))
print()
if choice not in [1, 2, 3, 4, 5]:
print("Please, enter a valid Input")
elif choice == 5:
break
else:
x = int(input("Enter first number: "))
y = int(input("Enter second number: "))
if (choice == 1):
print("RESULT -->", x, "+", y, "=", my_function.sum(x, y))
elif (choice == 2):
print("RESULT -->", x, "-", y, "=", my_function.subtraction(x, y))
elif (choice == 3):
print("RESULT -->", x, "*", y, "=", my_function.multiplication(x, y))
elif (choice == 4):
print("RESULT -->", x, "/", y, "=", my_function.division(x, y))
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment