Python Exercise 2 - Faulty Calculator | Python Tutorials For Absolute Beginners In Hindi #15

preview_player
Показать описание


Best Hindi Videos For Learning Programming:

Follow Me On Social Media
Рекомендации по теме
Комментарии
Автор

Hello Harry, thanks for the exercise! It was fun working on it. Here's the code:
n1=int(input("Enter your first number"))
n2=int(input("Enter your second number"))
opp=input("Choose operator (+ - * /)")
if opp=='+':
if n1==56 and n2==9:
print('77')
else:
print(n1+n2)
elif opp=='-':
print(n1-n2)
elif opp=='*':
if n1==45 and n2==3:
print('555')
else:
print(n1*n2)
elif opp=='/':
if n1==56 and n2==6:
print('4')
else:
print(n1/n2)

aarushikumar
Автор

Nice exercise, it triggers the methods to add some exclusions behaviors in thousands or millions normal cases.
Truly you are a wonderful tricky programmer.

r.k.rajoria
Автор

Pretty late to answer this but here we go!

# Design a calculator which can input 2 numbers and perform an operation according to the user.
# There must be a fault in the calculator. The fault must be, if the operation performed is 45*3(555), 56+9(77), 56/6=4
# the answer must be given accordingly, as per the brackets corresponding.
print("Welcome to the best calculator you will ever find for your math test!")
a=float(input("Enter your first number:"))
b=float(input("Enter your second number:"))
op=input("Enter the operation you want to perform (+, -, *, /):")
if (a, b)==(45, 3) and op=="*":
print("The answer is:555")
elif (a, b)==(56, 9) and op=="+":
print("The answer is:77")
elif (a, b)==(56, 6) and op=="/":
print("The answer is:4")
else:
if op=="+":
print("The answer is:", a+b)
elif op=="-":
print("The answer is:", a-b)
elif op=="*":
print("The answer is:", a*b)
elif op == "/":
print("The answer is:", a/b)
else:
print("Enter a valid operation.")


#Was preparing for entrances. So didn't consider programming after 10th boards. Feels great to code again!

rahulranjaniit-r
Автор

faulty_calc_var = {"56*5": "540", "45+19": "61", "56-18": "31"}
num1 = input("Enter the 1st number :")
print("Which operation you want to perform :")
operation = input()
num2 = input("Enter the second number :")
string = num1+operation+num2
if string in faulty_calc_var:

elif operation == "+":
print(int(num1)+int(num2))
elif operation == "*":

elif operation == "-":
print(int(num1)-int(num2))
elif operation == "/":
print(int(num1)/int(num2))

princeagnihotri
Автор

#Neat and clean code, i hope you will like it
# Faulty calculator
operator = input("Enter operator:")
val1 = int(input("Enter first operand = "))
val2 = int(input("Enter second operand = "))

if operator == "+":
if val1 == 56 and val2 == 9:
print("77")
else:
print("Sum is:", val1 + val2)
if operator == "-":
print("Substract is:", val1-val2)
if operator == "*":
if val1 == 45 and val2 == 3:
print("555")
else:
print("Multiply is :", val1*val2)
if operator == "/":
if val1 ==56 and val2 == 6:
print("4")
else:
print("Divide is:", float(val1/val2))

AmitGupta-iobr
Автор

#thank you harry bhai for teaching us
print("type :- ADD", "MULTIPLY", "DIVIDE", "MINUS" "\n to perform these operations")
e = input()
print("enter your 1st number")
x = int(input())
print("enter your 2nd number")
y = int(input())
print("your answer is")
if e=="MULTIPLY" :
if x==45 and y==3:
print("555")
else:
print(x*y)
elif e=="ADD" :
if x==56 and y==7 :
print("77")
else:
print(x+y)
elif e=="DIVIDE" :
if x==56 and y==6:
print("4")
else:
print(x/y)
elif e=="MINUS":
print(x-y)
else :
print("INVALID OPERATION")

flow-codm
Автор

Bhai Kya Excercise de diya..! bahar Hun Phir Bhi Maine Excercise book nikal ke code likhne laga!....Hope Calculator Faulty (Kam Karne Wala Ho jaye)

RohanDasRD
Автор

Thank you harry bhai for making this python course
var1=int(input("Enter the first no. for multiplication:"))
var2=int(input("Enter the second no. for multiplication:"))
if var1*var2==45*3:
print("Your result is 555")
else :
print("Your result is", var1*var2)
var4=int(input("Enter the first no.for addition:"))
var5=int(input("Enter the second no. for addition:"))
if var4+var5==56+9:
print("Your result is 77")
else:
print("Your result is ", var4+var5)
var7=int(input("Enter the first no. for division:"))
var8=int(input("Enter the second no. for division:"))
if var7/var8==56/6:
print("Your result is 4")
else:
print("Your result is", var7/var8)

vishwaskumar
Автор

a = int(input('enter your first no.: '))
b= int(input('enter your second number: '))
c = a+b
d = a*b
e = a/b
if a == (56 or 9) and b==(9 or 56):
print(77)
else:
print(c)
if a ==(45 or 3) and b == (3 or 45):
print(555)
else:
print(d)
if a == 56 and b == 6:
print(4)
else:
print(e)


Thankyou for making it easy for us

ashikajain
Автор

Hi harry, thanks for uploading these videos. I have a suggestion for you. I struggle all the time applying my programming knowledge after learning it practically. Can you give some small project to us after certain lectures so that we can develop our programming skill?

madhurnaredi
Автор

M a bit late, but love your channel, I'm in my first year now so started just now
love your exercises,
# Faulty Calculator
print("Enter your first number")
n1 = input()
print("Enter the function you want to perform. eg: +, -, *, /")
n2 = [input()]
print("Enter your second number")
n3 = input()
print("Answer:")
if "56" in n1 and "+" in n2 and "9" in n3:
print("56 + 9 = 77")
elif "45" in n1 and "*" in n2 and "3" in n3:
print("45 * 3 = 555")
elif "56" in n1 and "/" in n2 and "6" in n3:
print("56 / 6 = 4")
elif "+" in n2:
print(n1, "+", n3, "=", int(n1)+int(n3))
elif "-" in n2:
print(n1, "-", n3, "=", int(n1)-int(n3))
elif "*" in n2:
print(n1, "*", n3, "=", int(n1)*int(n3))
elif "/" in n2:
print(n1, "/", n3, "=", int(n1)/int(n3))
else:
print("ERROR")

aamanbhowmick
Автор

# FAULTY CALCULATOR
n1 = int(input("Enter 1st number: "))
n2 = int(input("Enter 2nd number: "))
op = input("Enter the operation you want to perform: ")
if op == '+':
if n1 == 10 and n2 == 20:
print('35')
else:
print(n1 + n2)
elif op == '-':
print(n1 - n2)
elif op == '*':
if n1 == 10 and n2 == 20:
print('300')
else:
print(n1 * n2)
elif op == '/':
if n1 == 20 and n2 == 10:
print('3')
else:
print(n1 / n2)

#THANKS SO MUCH HARRY FOR THIS PLAYLIST ITS REALLY HELPING ME & GREAT CONTENT

parthsarvaiya
Автор

i created it broo....

ope=input("enter the operation")
a=int(input("enter first number"))
b=int(input("enter the second number"))

if ope=="*" and a==56 and b==3:
print(555)
elif ope=="+" and a==56 and b==9:
print(77)
elif ope=="/" and a==56 and b==6:
print(4)

elif ope=="*":
print(a, "*", b, "=", a*b)
elif ope=="+":
print(a, "+", b, "=", a+b)
elif ope=="-":
print(a, "-", b, "=", a-b)
elif ope=="/":
print(a, "/", b, "=", a/b)
else:
print("abe chutiye operations matlab +-*/")

Yash.the.seeker
Автор

Thank you so much fo your efforts in this tutorial... 🙏

vincyjoseph
Автор

i have just started learning python . this is my first ever language to learn. here is my code:-


d1={"45*3":"555", "56+9":"67", "56/6":"4"}

print("Type your problem")
v1=input()

if v1 in d1:
print(d1.get(v1))
else:
print(eval(v1))

thanku Harry love love love.

amandeepkaur-jltr
Автор

Sorry for joining late, but I'll say this tutorial is helping me a lot. #Thanks Harry bhaiya.

ashwinikumar
Автор

# code with Harry : Solution -4

print("Enter first Number")
var_1 = int(input())
print("Enter second Number")
var_2 = int(input())
print("Enter Operator\n + for Addition \n - for subtraction \n * for multiplication \n / for division")
operator = input()
if operator == "+":
if int(var_1) == 56 and int(var_2) == 9:
result = 77
else:
result = int(var_1 + var_2)
print("Result = ", result)
elif operator == "-":
result = int(var_1-var_2)
print("Result = ", result)
elif operator == "*":
if int(var_1) == 45 and int(var_2) == 3:
result = 555
else:
result = int(var_1 * var_2)
print("Result = ", result)
elif operator == "/":
if int(var_1) == 56 and int(var_2) == 6:
result = 4
else:
result = int(var_1 / var_2)
print("Result = ", result)
else:
print("Invalid Operator entered")

testingapplications
Автор

#Faulty Calculator
print("Enter your First Number")
n1 = int(input())
print("Enter your Second Number")
n2 = int(input())
print("operator")
operator = (input())

if operator=="+":
if n1==55 and n2==9:
print(77)
else:
print(n1+n2)
elif operator=="*":
if n1==45 and n2==3:
print(555)
else:
print(n1*n2)
elif operator=="/":
if n1==56 and n2==6:
print(4)
else:
print(n1/n2)
elif operator=="-":
print(n1-n2)
else:
print("Invalid Entry")
Thank you, Harry bhai,

jainikshah
Автор

#this is simplest solution i guess and works for all the examples.
print("input first number")
a = int(input())
print("input second number")
b = int(input())
print("enter operator")
opr = input()

if a == 3 and b == 4 and opr == "+":
print("10") #wrong asnwer
elif a == 5 and b == 6 and opr == "/":
print("20") #wring answer
elif a == 5 and b == 6 and opr == "*":
print("25") #wrong asnwer
elif opr == "*":
print("the answer is", a * b)
elif opr == "/":
print("the answer is", a/b)
elif opr == "-":
print("the asnwer is ", a-b)
elif opr == "+":
print("the answer is ", a+b)

muhammadkashifkhattak
Автор

Keep going man, I have my resolution of 2019 to be awesome in Python and I know you can help me a lot.

PrinceKumar-krig