Python Exercise 2: Faulty Calculator Solution| Python Tutorials For Absolute Beginners In Hindi #19

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


Best Hindi Videos For Learning Programming:

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

Hi Harry, thank you for making python learning easy and fun.

print("Enter num1:")
num1=int(input())
print("Enter num2:")
num2=int(input())
print("Enter operator: +, *, /")
op=input()
if num1==43 and num2==3 and op=="*":
print("555")
elif num1==56 and num2==9 and op=="+":
print("77")
elif num1==56 and num2==6 and op=="/":
print("4")
elif op=="+":
print(num1 + num2)
elif op=="*":
print(num1 * num2)
elif op=="/":
print(num1 / num2)
else:
print("Invalid input")

NitinMestry
Автор

thanks sir for providing such a wonderful tutorial series, i have attempted the problem,

# Exercise 2
# This Calculator will give all results correctly except the three particular
# operations which shall show the following faulty results
# 45*3 = 555, 56+9=77, 56/6=4
while(True):
var1 = int(input("Enter the First Operand\n"))
var2 = int(input("Enter the Second Operand or exponent in case of power calculation\n"))
operator=input("Enter the Type of Operation, Available Operations: +, -, *, /, **, %\n")
if (max(var1, var2) == 45 and min(var1, var2) == 3 and operator == "*"):
print("Result:", "555")
elif (max(var1, var2) == 56 and min(var1, var2) == 9 and operator == "+"):
print("Result:", "77")
elif (var1== 56 and var2 == 6 and operator == "/"):
print("Result:", "4")
else:
if (operator == "+"):
print("Result:", var1 + var2)
elif (operator == "-"):
print("Result:", var1 - var2)
elif (operator == "*"):
print("Result:", var1 * var2)
elif (operator == "/"):
print("Result:", var1 / var2)
elif (operator=="**"):
print("Result:", var1 ** var2)
elif(operator=="%"):
print("Result:", var1 % var2)
if((input("Do you want to continue calculating? If yes type 'Y' else type 'N' \n")).capitalize()
=='Y'):
continue
else:
print("Thank You for using the Calculator")
break

#this is the code I came up with :-)

aritradas
Автор

Thanks Sir 🙏🙏🙏help learning programming online 🙏🙏🙏 thank-you so much

subratapriyanshi
Автор

while(True):
print("what type of operation you want to perform?\n"
"type + for addition\n"
"type - for subtraction \n"
"type * for multiplication\n"
"type / for division\n"
"type ** to raise the power\n")
operator = input("Enter operator:")
num1 = int(input("Enter your first number:\n"))
num2 = int(input("Enter your second number:\n"))
print("Answer:")
if operator == "+":
if num1 == 56 and num2 == 9:
print(77)
else:
print(num1 + num2)
elif operator == "/":
if num1 == 56 and num2 == 6:
print(4)
else:
print(num1 / num2)
elif operator == "*":
if num1 == 45 and num2 == 3:
print(555)
else:
print(num1 * num2)
else:
print(num1 - num2)
i = input("Do you wnat to use it again.Y/N:")
if i == "N":
break
if i == "Y":
continue

TheAstroG
Автор

print("Enter which operator you want to use")
a=input()
print("Enter your two values")
b=int(input())
c=int(input())

if a=='*':
if b==45 and c==3 :
print("the ans is 555")
else :
print("the ans is :", b*c)
elif a=='+':
if b==56 and c==9:
print("the ans is 77")
else:
print("the ans is :", b+c)
elif a=='/':
if b==56 and c==6:
print("the ans is 4")
else:
print("the ans is :", b/c)

aishwaryajadhav
Автор

Thanks Harry bhai for all, You are the best:


# Faulty Calculator :
# Done by Ravi Shukla

list= [45, 3, 56, 9, 6]

print("Enter the First value")
N1 = int(input())
print("Enter the Second value")
N2 = int(input())

if N1 and N2 in list:
N1 = N1 + 10
N2 = N2 + 20
print("What you want to perform with these numbers (+, -, *, /)")
N3 = input()

if N3 == '+':
N4 = float(N1) + float(N2)
print("The sum of both number is ", N4)

elif N3 == '-':
N4 = float(N1) - float(N2)
print("The Substraction of these number is", N4)

elif N3 == '*':
N4 = float(N1) * float(N2)
print("The Multiplication of these number is", N4)

elif N3 == '/':
N4 = float(N1) / float(N2)
print("The Division of these number is", N4)

else:
print("What you want to perform with these numbers")
N3 = input()

if N3 == '+':
N4 = float(N1) + float(N2)
print("The sum of both number is ", N4)

elif N3 == '-':
N4 = float(N1) - float(N2)
print("The Substraction of these number is", N4)

elif N3 == '*':
N4 = float(N1) * float(N2)
print("The Multiplication of these number is", N4)

elif N3 == '/':
N4 = float(N1) / float(N2)
print("The Division of these number is", N4)

ravishukla
Автор

shanti bhushan here, below is my program
def product(a, b):
if a==45 and b==3:
return 555
else:
return int(a)*int(b)

def sum(a, b):
if a==56 and b==9:
return 77
else:
return int(a)+int(b)

def div(a, b):
if a==56 and b==6:
return 4
else:
return int(a)/int(b)

calc=input("enter the choice from sum, product and division")
if calc=="product":
x=int(input("enter number 1"))
y=int(input("enter number 2"))
print(product(x, y))
elif calc=="sum":
x = int(input("enter number 1"))
y = int(input("enter number 2"))
print(sum(x, y))
elif calc=="division":
x = int(input("enter number 1"))
y = int(input("enter number 2"))
print(div(x, y))

rogerthat
Автор

n = 18
lifes = 5
while lifes != 0 :
user = int(input("Type a number\n"))
if user > n:
print("Too high")
lifes -= 1
if lifes == 0:
print("You loose")
else:
print(f"{lifes} lives remaining")
elif user < n:
print("Too low")
lifes -= 1
if lifes == 0:
print("You loose")
else:
print(f"{lifes} lives remaining")
else:
print(f"You won in {5-lifes} guesses")
print("You won")

ronitpanda
Автор

a=int(input("Enter 1st number:"))
b=int(input("Enter 2nd number:"))

if a is 45 and b is 3:
print("faulty calc")
else:
print(a*b)
if a is 56 and b is 9:
print("faulty calc")
else:
print(a+b)
if a is 56 and b is 6:
print("faulty calc")
else:
print(a/b)

shyamalmulani
Автор

#I know i was late to give the solution of this problem but i joined your channel late, but trust me you are very good in your work. I learn many things from your channel and i appreciate your efforts bro. Thanks bhai.

a=int(input("Enter the first Number:"))
b=int(input("Enter the second number:"))
operator=input("Enter the operator:")
if a==45 and b==3 and operator=='+':
print("555")
elif a==56 and b==9 and operator=='+':
print('77')
elif a==56 and b==6 and operator=='/':
print('4')
elif operator=="+":
print(a+b)
elif operator=="/":
print(a/b)
elif operator=="-":
print(a-b)
elif operator=="*":
print(a*b)
else:
print("Error, please re enter the numbers.")

rapidknowledge
Автор

Yu are great sir....
Your phython tutorial is best for those students who can not afford high Coching.. you are really great....God helps you.

exclusiveglobaleducation
Автор

a=int(input("enter your first number"))
b=int(input("enter you second number"))
if a== 45 and b==3:
print("product is 555")
elif a==56 and b==9:
print("addition is 77")
elif a==56 and b==4:
print(" the division value is 4")

product=a*b
print(product, "is the product")
division=a/b
print(division, "is the division value")

bibek.official
Автор

# faulty cal
#take operator then take opr5ands then calculate but follow some case
# Design a calculator which will correctly solve all the problems excepts the following ones:
#45+3=555, 56+9=77, 56/6=4
n1=int(input("Enter the first first value"))
n2=int(input("Enter the first first value"))
opr= input("What operation do you want Sir: please mention "
"\nlike = + * - / ")
if opr == "+":
if n1==45and n2==3:
print("555")
else:
print(n1+n2)

elif opr=="-":
if n1==56 and n2==9:
print("77")
else:
print(n1-n2)

elif opr=="/":
if n1 == 56 and n2 == 9:
print("4")
else:
print(n1/n2)
elif opr == "*":
print(n1*n2)
else:
print(n1%n2)

shivamseth
Автор

Harry sir, Currently i am watching all of your Python Videos but once this finished i wish to learn SQL from your videos .

pahadi_dev
Автор

print('Welcome to the calculator world!!')
print('Please type the math operation you want to complete')
print("+ for addition \n - for subraction \n * for multiplication \n / for division \n ** for power \n % for modulus")
while(True):
num1 = int(input('Enter the first number: '))
num2 = int(input('Enter the second number: '))
operator = input('Which operator do you want to use?: ')

if operator == '+':
if num1 == 56 and num2 == 9:
print(77)
else:
print(num1 + num2)

if operator == '-':
print(num1 - num2)

if operator == '*':
if num1 == 45 and num2 == 3:
print(555)
else:
print(num1 * num2)

if operator == '/':
if num1 == 56 and num2 == 6:
print(4)
else:
print(num1 / num2)

if operator == '**':
print(num1 ** num2)

if operator == '%':
print(num1 % num2)

again = input(
'Do you want to use Calculator again? \n Press y for yes and n for no: ')
if again == 'y':
continue
else:
print('See you again!')
break

hetmahendragala
Автор

n=45
i=0
while (True):
a=int(input("enter a number\n"))
if a>45:
print("the value is smaller than", a)
elif a<45:
print("the value is greater than", a)
else:
print("congrats")
i = i + 1
if (i < 10):
print("no of guess left", 10-i)
continue
else:
print("game over you loose\n")
break

manishnegi
Автор

Thanks sir, for this amazing course....

shoaibmulani
Автор

Thank you Harry for sharing your knowledge in EFFECTIVE way that people like me are able to cope up with this. I have one feedback, please write your code as well because you review the code written in comments, now everyone might have different logic so it would be really helpful if you can write an optimum code so that we can also learn new things from that (I agree that there cant be one definite way of writing code however). With that it would really easy for us to follow along. Thanks again and keep up the good work. And please share your LinkedIn ID, I would like to promote you on that as well.

gauravsharma
Автор

while(1):
print("Guess a number")
inp = int(input())
inp1 = 18
if inp==inp1:
print("Congratulation you gussed the number")
break
elif inp<inp1:
print("Enter a large number")
continue
elif inp>inp1:
print("Enter a small number")
continue
My name is Aarav tyagi

AaravTyagi-tz
Автор

"""
we need to make a faulty calculator for the following case and except that
it should show correct values
45*3 = 555, 56+9 =77, 56/9=4
"""
num1=int(input("enter the first number\n"))
num2=int(input("Enter the second number\n"))
operator=input("Enter the operator you need to perform /, *, -, +\n")

if num1==45 and num2==3 and operator=='*':
print(555)
elif num1==56 and num2==9 and operator=='+':
print(77)
elif num1==56 and num2==9 and operator=='/':
print(4)
elif operator=='+':
print(num1+num2)
elif operator=='*':
print(num1*num2)
elif operator=='/':
print(num1/num2)
else:
print("you have done wrong calcualtion")

vichithara