Faulty Calculator In Python With Code
Last updated June 21, 2023 by Jarvis Silva
In this tutorial I will show you how to create faulty calculator in python with source code, a faulty calculator is a calculator which does all the basic operations but in some cases specified by the programmer it will print faulty result.
Python Code For Faulty Calculator
num1 = int(input("Enter a number: "))
num2 = int(input("Enter another number: "))
operation = input("What operation do you want to do (+,-,/,*): ")
if operation == "+":
# Change if condition values according to you
if num1 == 1 and num2 == 3:
print(97)
else:
print(num1 + num2)
elif operation == "-":
# Change if condition values according to you
if num1 == 5 and num2 == 2:
print(327)
else:
print(num1 - num2)
elif operation == "*":
# Change if condition values according to you
if num1 == 2 and num2 == 9:
print(357)
else:
print(num1 * num2)
elif operation == "/":
# Change if condition values according to you
if num1 == 4 and num2 == 2:
print(99)
else:
print(num1 / num2)
Above is the python faulty calculator program, in the program we simply add if condition for a specific numbers when the user trys to do calculation for them it will print a faulty result.
You can run this program and see the result yourself so inorder to run it you need to have python installed on your computer, If you don’t have then follow this guide: Install and setup python on your computer.
After running this program you will see that it asks you to enter two numbers and the operation you want to perform then it will check if the entered numbers match the faulty conditions or not if not then it will print the real result if matches it prints the faulty result you entered below is an example output.
Enter a number: 2
Enter another number: 9
What operation do you want to do (+,-,/,*): *
357
As you can see we successfully created this program in python, Don’t want to create all the files and folders then you can run this program now using this online python compiler.
Here are some more python program tutorials for you:
- Check If Backslash In String In Python.
- Python Program To Check If A Variable Is A Function.
- Python Program To Check If A Variable Is A Dictionary.
- Python Program To Check Even Or Odd Numbers.
- Python Program To Check Composite Numbers.
- Python Program To Check Whether A Person Is Senior Citizen Or Not.
- Python Program To Check Whether A Person Is Eligible To Vote Or Not.
- Love Calculator Program In Python With Code.
I hope you found what you were looking for from this tutorial, and if you want more python programs and tutorials like this, do join our Telegram channel for future updates.
Thanks for reading, have a nice day 🙂