Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 我怎样才能使选项B正常工作,因为最后一个答案不太有效_Python 3.x - Fatal编程技术网

Python 3.x 我怎样才能使选项B正常工作,因为最后一个答案不太有效

Python 3.x 我怎样才能使选项B正常工作,因为最后一个答案不太有效,python-3.x,Python 3.x,我需要它,所以如果你选择选项B,你可以输入一个数字,它会告诉你它是否是一个浮点数。有点像,如果你选择一个选项,然后输入一个数字,它会让你输入一个数字,然后告诉你它是否是一个整数 这是我的代码: def getNumber(): while True: try: userInput = int(input("What number would like to test as an integer ? "))

我需要它,所以如果你选择选项B,你可以输入一个数字,它会告诉你它是否是一个浮点数。有点像,如果你选择一个选项,然后输入一个数字,它会让你输入一个数字,然后告诉你它是否是一个整数

这是我的代码:

def getNumber():
    while True:
        try:
            userInput = int(input("What number would like to test as an integer ? "))
            return userInput
        except ValueError as ve:
            print("Not an integer! Try again.")
            continue

print("What would you like to do?")
print("Option A = Interger")
print("Option B = Floating Point")
Msg = input()
if Msg == 'A':
    integer_received = getNumber()
    print(integer_received, "is an int !")
else:
    print("You did not choose 'A' or 'B', make sure it is capitalized!")
def getNumber():
    while True:
        try:
            userInput = int(input("What number would like to test as an integer ? "))
            return userInput
        except ValueError as ve:
            print("Not an integer! Try again.")
            continue

def getFloatintNumber():
    while True:
        try:
            userInput = float(input("What number would like to test as float ? "))
            return userInput
        except ValueError as ve:
            print("Not a float! Try again.")
            continue


print("What would you like to do?")
print("Option A = Interger")
print("Option B = Floating Point")
Msg = input()
if Msg == 'A':
    integer_received = getNumber()
    print(integer_received, "is an int !")
elif Msg == 'B':
    float_received = getFloatintNumber()
    print(float_received, "is a float !")
else:
    print("You did not choose 'A' or 'B', make sure it is capitalized!")