如何在python3中获取用户的float和float输入?在Apparently programmed a calculator, but i would love for user's input to be in int and float not just int or float but both. That's basically all am concerned about, changing the int to get int and float. Sadly Java uses double.def calculator():
def add(x, y):
return x + y
def sub(x, y):
return x - y
def mul(x, y):
return x * y
def div(x, y):
return x / y
def power(x, y):
return x ** y
def modulus(x, y):
return x % y
print(""" -- Select Operation --
1. Addition
2. Subtraction
3. Multiplication
4. Division
5. Power
6. Modulus
""")
choice = input("Enter 1 or 2 or 3 or 4 or 5 or 6 from the Select Operation >> ")
while choice not in ('1', '2', '3', '4', '5', '6'):
choice = input("Invalid Input! Please Enter 1 or 2 or 3 or 4 or 5 or 6 from the Select Operation >> ")
print("\n")
print("============================================================")
print("Gathering data...")
# How to make user input in both int and float not int alone?
num1 = int(input("Enter First number >> "))
num2 = int(input("Enter Second number >> "))
if choice == '1':
print(num1, "+", num2, "=", add(num1, num2))
elif choice == '2':
print(num1, "-", num2, "=", sub(num1, num2))
elif choice == '3':
print(num1, "*", num2, "=", mul(num1, num2))
elif choice == '4':
print(num1, "/", num2, "=", div(num1, num2))
elif choice == '5':
print(num1, "^", num2, "=", power(num1, num2))
elif choice == '6':
print(num1, "%", num2, "=", modulus(num1, num2))
repeat_cal()
def repeat_cal():
print("Do you want to Select Operation again")
choose_again = input("Enter Y for YES or N for NO>> ")
if choose_again.upper() == 'Y':
calculator()
elif choose_again.upper() == 'N':
print("-----------------Good Bye!---------------------------")
exit()
else:
repeat_cal()
calculator()