Popular Posts

Thursday, August 27, 2020

Python Beginner: Building a Better Calculator

 Hello, developer!


Hope you are having confidence on Python programming! You can get input from user, printing out results with your data type, making lists & tuples, building functions and using if statements.


Today, we will build up a upgraded calculator. It supports add, subtract, multiplying and division of 2 input numbers.


I showed the better calculator codes and execution result as following.

num1 = float(input("Enter first number: "))
op = input("Enter operator: ")
num2 = float(input("Enter second number: "))

if op == "+":
print(num1 + num2)
elif op == "-":
print(num1 - num2)
elif op == "/":
print(num1 / num2)
elif op == "*":
print(num1 * num2)
else:
print("Invalid operator")


Can you see the same result on your PC? Great job! I recommend you have some time to improve this calculator with more useful calculation features.


See you on the next post, developer! 😊


  


No comments:

Post a Comment

Python - Web crawling exercises

Hello Python developer! How are you? Hope you've been good and had wonderful time with Python. There are 10 Python requests module exerc...