calculadora simple de python
#Store number variables for the two numbers
num1 = input('Enter first number: ')
num2 = input('Enter second number: ')
#the sum of the two numbers variable
sum = float(num1) + float(num2)
sum2 = float(num1) - float(num2)
sum3 = float(num1) * float(num2)
sum4 = float(num1) / float(num2)
#what operator to use
choice = input('Enter an operator, + = addition, - = subtraction, * = multiplication and / = division: ')
#different sums based on the operators
if choice == '+':
print('The sum of {0} and {1} is {2}'.format(num1, num2, sum))
if choice == '-':
print('The sum of {0} and {1} is {2}'.format(num1, num2, sum2))
if choice == '*':
print('The sum of {0} and {1} is {2}'.format(num1, num2, sum3))
if choice == '/':
print('The sum of {0} and {1} is {2}'.format(num1, num2, sum4))
cómo hacer una calculadora usando idle
def calculate():
operation = input('''
Please type in the math operation you would like to complete:
+ for addition
- for subtraction
* for multiplication
/ for division
''')
number_1 = int(input('Please enter the first number: '))
number_2 = int(input('Please enter the second number: '))
if operation == '+':
print('{} + {} = '.format(number_1, number_2))
print(number_1 + number_2)
elif operation == '-':
print('{} - {} = '.format(number_1, number_2))
print(number_1 - number_2)
elif operation == '*':
print('{} * {} = '.format(number_1, number_2))
print(number_1 * number_2)
elif operation == '/':
print('{} / {} = '.format(number_1, number_2))
print(number_1 / number_2)
else:
print('You have not typed a valid operator, please run the program again.')
# Add again() function to calculate() function
again()
def again():
calc_again = input('''
Do you want to calculate again?
Please type Y for YES or N for NO.
''')
if calc_again.upper() == 'Y':
calculate()
elif calc_again.upper() == 'N':
print('See you later.')
else:
again()
calculate()
calculadora básica en python
#My Personal Python calculator
print("My Personal Python calculator")
#inputs
num1 = int(input('Enter the first number: '))
num2 = int(input('Enter the second number: '))
#opration req
opr = input('Enter the type of operation you want to perform between your chosen two numbers: ')
#calculation
if opr=='+':
ans = num1 + num2
# displaying the answer
print(f'Your final answer is {ans}')
elif opr == '- ':
ans = num1 - num2
# displaying the answer
print(f'Your final answer is {ans}')
elif opr=='*':
ans = num1 * num2;
# displaying the answer
print(f'Your final answer is {ans}')
elif opr=='/':
ans = num1 / num2
# displaying the answer
print(f'Your final answer is {ans}')
else:
print('Invalid Entry!!!')
cómo hacer una calculadora en python
# This will be one of the most advanced results you will find.
# We will be using classes and simple operators like +,-,*,/
class Calculator:
def addition(a,b):
return a + b
def subtraction(a,b):
if a<b:
return b - a
else:
return a - b
def multiplication(a,b):
return a * b
def division(a,b):
if a<b:
return b / a
else:
return a / b
# You can do this in terminal.
<C:/Users/username>python
>>> from main import Calculator
>>> result = Calculator.[addition|subtraction|multiplication|division](anyNumber, anyNumber)
>>> print(result)
cómo hacer una calculadora de python
#Calculator
import time
def add():
n1 = input('Enter a number: ')
n2 = input('Enter another number: ')
time.sleep(1)
print(int(n1)+int(n2))
def multiply():
n1 = input('Enter a number: ')
n2 = input('Enter another number: ')
time.sleep(1)
print(int(n1)*int(n2))
def divide():
n1 = input('Enter a number: ')
n2 = input('Enter another number: ')
time.sleep(1)
print(int(n1)int(n2))
def subtract():
n1 = input('Enter a number: ')
n2 = input('Enter another number: ')
time.sleep(1)
print(int(n1)-int(n2))
run = True
while run:
ans = input('Select an opreation: ')
if(ans=='Addition'):
add()
if(ans=='Divide'):
divide()
if(ans=='Multiply'):
multiply()
if(ans=='Subtract'):
subtract()
calculadora sencilla en python
#Simple Calculator Program in Python by Rupesh Singh
def sum1(first_input, second_input): # Sum function "+"
result1 = first_input + second_input
print("Your Answer is:-", result1)
return
def minus(first_input, second_input): # Minus function "-"
result2 = first_input - second_input
print("Your Answer is:-", result2)
return
def multi(first_input, second_input): # Multiplication function "*"
result3 = first_input * second_input
print("Your Answer is:-", result3)
return
def div(first_input, second_input): # Division function "/"
result4 = first_input / second_input
result4 = float(round(result4))
print("Your Answer is:-", result4)
return
# User Input
first_input = int(input("Enter your 1st Input:- "))
command = input("What you want to do (+, -, *, /):- ")
second_input = int(input("enter your 2nd Input:- "))
if command == "+":
sum1(first_input, second_input)
elif command == "-":
minus(first_input, second_input)
elif command == "*":
multi(first_input, second_input)
elif command == "/":
div(first_input, second_input)
else:
print("Command Error!")