Making Calculator Using Python | CodeCarnival | #python

preview_player
Показать описание
In this tutorial, I'll walk you through the process of building a calculator using Python. Join us as we explore the fundamentals of Python programming and apply them to create a fully-functional calculator. We'll cover topics like variables, functions, and control flow to help you understand how to write code that performs basic arithmetic operations. This video is perfect for anyone interested in learning more about programming with Python or for those looking to build a calculator from scratch. #Python #Calculator #CodingTutorial #CodeCarnival

source code:
# This program implements a basic calculator using if-else and elif statements

# Ask user to enter two numbers and the operation to perform
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
operator = input("Enter operator (+, -, *, /): ")

# Use if-else and elif statements to perform the operation based on the operator entered
if operator == '+':
result = num1 + num2
elif operator == '-':
result = num1 - num2
elif operator == '*':
result = num1 * num2
elif operator == '/':
result = num1 / num2
else:
print("Invalid operator")
exit()

# Print the result
print(num1, operator, num2, "=", result)

thnx for watching
Рекомендации по теме
visit shbcf.ru