python3输入float_如何为python3获取用户的int和float输入

如何在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()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值