Комментарии:
a=float(input("Enter first number:"))
b=float(input("Enter second number:"))
print("Sum=",a+b)
print("Subtraction=",a-b)
print("Product=",a*b)
print("Division=",a/b)
print("Remainder=",a%b)
Isnt this better and easy?
Actually they also gave me as assignment
ОтветитьIs good😂
ОтветитьHey how do i get rid of the errors it doesnt let me start the thing
ОтветитьJust wanna share my comments:
You can declare the numbers so you’ll have reusable function:
def get_nums():
x = float(input('Enter 1st number: '))
y = float(input('Enter 2nd number: '))
return x, y
and simply assign it to your operations function like this:
def sum(x, y):
return x + y
inside your loop you can do this instead:
x, y = get_nums()
so you don’t have to repeat it…
if operation == '1':
result = sum(x, y)
you can use fstring instead to make it simplified.
print(f'The Sum of {x} and {y} is {result}')
also put error handling on your division operation:
if y is equal to zero, you can print cannot divide by zero.
Overall, it' s really nice. Thanks for sharing your knowledge.
Highlh recommended
Ответитьyour teaching is brilliant please keep going
Ответитьpls paste the code next time
Ответить1 line calculator: print(eval(input()))
ОтветитьCan you please share your WhatsApp number with me
ОтветитьI git an error at minus i needed to add an coma after the twxt xan someone explain?😅
ОтветитьDo you deal With Software While Implementing These Programs?🤯
ОтветитьThis was such an amazing tutorial. Wonderful to follow and easy to understand! Keep up the great work.
ОтветитьThis is a basic calculator for beginners and he did a good job, pretty weird of people to be flexing more complex ones in the comments that involve learning about float, it's for b.e.g.i.n.n.e.r.s float is what stops you sink to beginner.
ОтветитьThanks again
ОтветитьVery helpful bro keep on going -_-
Ответитьhi guys, i am trying to get to this programming thing, im looking for exercises for me to practice what i am learning, i just watch this video and i found a different way to code this calculator, and i would like to see if theres is something that could improve on this:
n1 = int(input('WHAT IS THE FIRST NUMBER? '))
n2 = int(input('WHAT IS THE SECOND NUMBER? '))
print ('SELECT AN OPERATION')
print('1. ADD')
print('2. SUBTRACT')
print('3. DIVIDE')
print('4. MULTIPLY')
OPERATION = input()
if OPERATION == '1':
RESULT = n1 + n2
elif OPERATION == '2':
RESULT = n1 - n2
elif OPERATION == '3':
RESULT = n1 / n2
elif OPERATION == '4':
RESULT = n1 * n2
else:
print('INVALID INPUT')
print(RESULT)
elif is red for me. did I do something wrong?
operation = input()
if operation == 1:
elif operation == 2:
elif operation == 3:
elif operation == 4:
I'm using visual code studio if you ask me
I think instead of using
operation = input()
if operation == “1”
You can use
operation = int(input()
If you want it to run without error instead of int use float() so if the user enters ‘1.5’ it’ll come back as invalid entry instead of error.
Also if you used int instead of float on num1 etc it will not read floats (numbers with a decimal)
Hii I have also upload one short on my channel which also includes creation of calculator program in python in script mode.
First time I have ever made a video related to python language .
please watch it once 🙏🙏
plzz plzzz
Hii I have also upload one short on my channel which also includes creation of calculator program in python in script mode.
First time I have ever made a video related to python language .
please watch it once 🙏🙏
plzz plzzz
Hii I have also upload one short on my channel which also includes creation of calculator program in python in script mode.
First time I have ever made a video related to python language .
please watch it once 🙏🙏
plzz plzzz
Bruh is just stuck with his own problems
ОтветитьI´ve got the same errors, thanks for the help :)
ОтветитьThank you for this. I didn't know how to go about this but you just simplified it in 15 mins. Thank you so much
Ответитьdude i think u need to learn the calculator first
Ответитьim trying to build my own calculator in python but the + operator doesnt work properly, like im typing 1 as num1 and 3 as num2 but the program just prints out '13'
Ответить3 and 4 code are enterchange
ОтветитьThank you, you made it sooooo simple❤❤😊
Ответитьthank you
ОтветитьI just start to study Phyton this days but... at first, you dont need FIVE prints, right? I think if you just write with " " " should works; something like this:
print("""Select an operation to perfom:
1. Add
2. Subtract
3. Multiply
4. Divide
""")
hllo
ОтветитьOkay but where's the calculator u built tho ?
ОтветитьNice
Thanks a lot
How to import fraction to this calculator?
Ответитьa bit different.
while True:
print("addition 1:")
print("subtract 2:")
print("multiply 3:")
print("division 4:")
operation = input("Enter Number 1-4: ")
num1 = float(input("Enter Number: "))
num2 = float(input("Enter Number: "))
if operation == "1":
print(num1, "+", num2, "=", (num1+num2))
elif operation == "2":
print(num1, "+", num2, "=", (num1-num2))
elif operation == "3":
print(num1, "+", num2, "=", (num1*num2))
elif operation == "4":
print(num1, "+", num2, "=", (num1/num2))
else:
print("invalid submission")
thank you
ОтветитьThank you so much ☺️
Ответитьcan you say me what i did wrong? i have 21 errors
rint("Select an operation to perform: ")
print("1. ADD")
print("2. SUBTRACT")
print("3. MULTIPLY")
print("4. DIVIDE")
operation = input()
if operation == "1":
num1 = input("Enter first number: ")
num2 = input("Enter second number: ")
print("The sum is " + str(int(num1) + (int(num2)))
elif operation == 2:
num1 = input("Enter first number: ")
num2 = input("Enter second number: ")
print("The sum is " + str(int(num1) - (int(num2))))
elif operation == 3:
num1 = input("Enter first number: ")
num2 = input("Enter second number: ")
print("The sum is " + str(int(num1) * (int(num2))))
elif operation == 4:
num1 = input("Enter first number: ")
num2 = input("Enter second number: ")
print("The sum is " + str(int(num1) / (int(num2))))
else:
print("Invalid Entry")
I keep getting invalid syntax anytime I run my code
ОтветитьThis is really great. I like the way you intentionally made those mistakes to teach us what could cause any error.
You're a good teacher.
Bruh I need a calculator programm which can accept multiple inputs
ОтветитьThank you so much!
ОтветитьThanks brother. (Channel subscribed)
Ответитьx = float(input("ENTER FIRST NUMBER :"))
opreater = input("enter operater (+,-,*,/) :")
y = float(input("ENTER SECOND NUMBER :"))
if opreater == "+":
print(x + y)
elif opreater == "-":
print(x - y)
elif opreater == "*":
print(x * y)
elif opreater == "/":
print(x / y)
else:
print("invalid syntex")
One simplest calculator 😃😃
Thanks!
Ответитьi can code in 1 line
while True: print(f"ANS : {eval(input('> '))}")
And the sum shows "45"😂
ОтветитьNice video, I did it
Btw how can I make it reusable
how can you fix this?
Ответить