Python Exercise 2 - Faulty Calculator

Code file as described in the video

# Exercise 2 - Faulty Calculator
# 45 * 3 = 555, 56+9 = 77, 56/6 = 4
# Design a calculator which will correctly solve all the problems except
# the following ones:
# 45 * 3 = 555, 56+9 = 77, 56/6 = 4
# Your program should take operator  and the two numbers as input from the user
# and then return the result


Comments(8)

mmishra at 2019-06-23 09:30:09 says
print("Enter 1st number:",end=" ") Number1 = int(input()) print("Enter 2nd number:",end=" ") Number2 = int(input()) print("Enter operator +,-,*,/ on numbers:",end=" ") Operator = input() if (Number1 == 45 and Number2 == 3 or Number1 == 3 and Number2 == 45) and Operator == '*': print(Number1, Operator, Number2, " = ", 7777) elif (Number1 == 56 and Number2 == 9 or Number1 == 9 and Number2 == 56) and Operator == '+': print(Number1, Operator, Number2, " = ", 77) elif (Number1 == 56 and Number2 == 6 or Number1 == 6 and Number2 == 56) and Operator == '/': print(Number1, Operator, Number2, " = ", 4) else: if Operator == '*': print(Number1, Operator, Number2, " = ",Number1*Number2) elif Operator == '+': print(Number1, Operator, Number2, " = ",Number1 + Number2) elif Operator == '-': print(Number1, Operator, Number2, " = ",Number1 - Number2) elif Operator == '/': print(Number1, Operator, Number2, " = ",Number1 / Number2) else: print("Unable to calculate, wrong operator")
thakurabhi at 2019-06-23 09:30:09 says
print("Enter first number ") N1 = int(input()) print("Enter your operation + , - , / , * ") op = (input()) print("Enter 2nd number ") N2 = int(input()) if (N1 == 45 and N2 == 3 or N1 == 3 and N2 == 45) and op == '*': print(N1,op,N2, " = " , 555) elif (N1 == 56 and N2 == 4 or N1== 4 and N2 == 56) and op == '+': print(N1,op,N2, " = " , 77) elif (N1 == 56 and N2 == 6 or N1 == 6 and N2 == 5656) and op == '/': print(N1,op,N2, " = " , 4) else: if op == '+': print(N1,op,N2, " = ", N1 + N2) elif op == '*': print(N1,op,N2, " = ", N1 * N2) elif op == '/': print(N1,op,N2, " = ", N1 / N2) elif op == '-': print(N1,op,N2, " = ", N1 - N2) else: print("over")
Manav_Seng at 2019-06-23 09:30:09 says
Name: Manav Sengupta Solution: # CodewithHarry Python Excercise 2- Faulty Calculator Number_1=float(input("Enter the First Number")) Number_2=float(input([float(input("Enter the Second Number"))])) operator = input("Enter 'add' for Addition ; \nEnter'sub' for Subtraction ; \nEnter 'mul' for Multiplication ; \nEnter 'div' for Division") if ((Number_1 == 45 and Number_2 == 3 and operator=='mul') or (Number_1 == 56 and Number_2 == 6 and operator=='div') or (Number_1 == 56 and Number_2 == 9 and operator=='add')): if (Number_1 == 45): print("The Answer is : 555") elif (Number_2 == 9): print("The Answer is : 74") else: print("The Answer is 4") else: if(operator=='add'): Answer=Number_1+Number_2 elif(operator=='sub'): Answer=Number_1-Number_2 elif(operator=='mul'): Answer=Number_1*Number_2 elif(operator=='div'): Answer=Number_1/Number_2 else: Answer="Sorry Invalid Input" print("The Answer is : "+Answer) print(147*"*"+"\n*"+145*" "+"*\n*"+9*" "+"Thanks for checking out my code, and a ton of thanks to CodewithHarry Channel for all the Quality Content for Free"+22*" "+"*\n*"+145*" "+"*\n"+147*"*") # Gratitude
Manav_Seng at 2019-06-23 09:30:09 says
sorry i screwed it..... here is the correct one: # CodewithHarry Python Excercise 2- Faulty Calculator Number_1=float(input("Enter the First Number")) Number_2=float(input("Enter the Second Number")) operators = input("Enter 'add' for Addition ; \nEnter'sub' for Subtraction ; \nEnter 'mul' for Multiplication ; \nEnter 'div' for Division") if ((Number_1 == 45 and Number_2 == 3 and operators=='mul') or (Number_1 == 56 and Number_2 == 6 and operators=='div') or (Number_1 == 56 and Number_2 == 9 and operators=='add')): if (Number_1 == 45): print("The Answer is : 555") elif (Number_2 == 9): print("The Answer is : 74") else: print("The Answer is 4") else: if(operators=='add'): Answer=Number_1+Number_2 elif(operators=='sub'): Answer=Number_1-Number_2 elif(operators=='mul'): Answer=Number_1*Number_2 elif(operators=='div'): Answer=Number_1/Number_2 else: Answer="Sorry Invalid Input" print("The Answer is : "+str(Answer)) print(147*"*"+"\n*"+145*" "+"*\n*"+9*" "+"Thanks for checking out my code, and a ton of thanks to CodewithHarry Channel for all the Quality Content for Free"+22*" "+"*\n*"+145*" "+"*\n"+147*"*") # Gratitude
zadrain at 2019-06-23 09:30:09 says
#45*3=555 #56+9 = 77 #56/6 =4 first_number = int(input("1st number")) second_number = int(input("2nd number")) operator = (input("choose operator")) if first_number ==45 and second_number==3 and operator=="*": print("555") elif first_number ==56 and second_number==9 and operator=="+": print("77") elif first_number ==56 and second_number==6 and operator=="/": print("4") else: if operator=="+": print(first_number + second_number) elif operator=="*": print(first_number * second_number) elif operator=="/": print(first_number / second_number) elif operator=="-": print(first_number - second_number)
AR78692 at 2019-06-23 09:30:09 says
put1=int(input('Enter your first number:')) operator=input('Enter your operatior + - / *:') put2=int(input('Enter your second number:')) #for addition if operator=='+': if put1==56 and put2==9: put3=77 print('your total add is:',put3) else: print('Your total add is:',put1+put2) #for subtraction if operator=='*': if put1==45 and put2==3: put3=555 print('Your total multipluction is:',put3) else: print('your total multipluction is:',put1*put2) #for division if operator=='/': if put1==56 and put2==6: put3=4 print('Your division is:',put3) else: print('your total division is:',put1/put2)
GaziAbbas at 2019-06-23 09:30:09 says
# Exercise 2 - Faulty Calculator # 45 * 3 = 555, 56+9 = 77, 56/6 = 4 # Design a calculator which will correctly solve all the problems except # the following ones: # 45 * 3 = 555, 56+9 = 77, 56/6 = 4 # Your program should take operator and the two numbers as input from the user # and then return the result print("Note: Please Enter Only (+,-,/,*) Operator Only\n Please Input Only Non-Decimal Value") oprtr = input("Enter Operator: ") num1 = int(input("Enter First Number: ")) num2 = int(input("Enter Second Number: ")) ans = 0 oprtionPerofomed = True if oprtr == '+': if ((num1 == 56 and num2 == 9) or (num1 == 9 and num2 == 56)): ans = 77 else: ans = num1 + num2 elif oprtr == '-': ans = num1 - num2 elif oprtr == '*': if ((num1 == 45 and num2 == 3) or (num1 == 3 and num2 == 45)): ans = 555 else: ans = num1 * num2 elif oprtr == '/': if ((num1 == 56 and num2 == 6) or (num1 == 6 and num2 == 56) ): ans = 4 else: ans = num1 / num2 else: print("Please Select Proper Operator") oprtionPerofomed = False if oprtionPerofomed: print(" ", num1, " ", oprtr, " ", num2, " = ", ans)
sushil2002 at 2019-06-23 09:30:09 says
# Exercise 2: faulty calci #*+/ num1=int(input("enter a number ")) op=input("enter operator(+,-,*,/") if op== "+": num2 = int(input("enter another number to perform operation")) print("result=",555) elif op=="*": num2 = int(input("enter another number to perform operation")) print("result=",386) elif op=="/": num2 = int(input("enter another number to perform operation")) print("result=",54) elif op=="-": num2=int(input("enter another number to perform operation")) print("result=",num1-num2) else: print("invalid operator")