python:如何仅输出整数和浮点列表中的整数

python:如何仅输出整数和浮点列表中的整数,python,python-3.x,Python,Python 3.x,我有个问题。我想知道是否有一种方法可以只输出整数和浮点数列表中的整数 这就是我到目前为止所写的:(对它的格式感到抱歉) 我不希望它显示长小数,只显示整数。我想你想问的是,“我如何确定一个数字是否可以被另一个数字平均整除?” 这个问题的答案是 模运算基本上返回两个数除后的整数余数。因此,6%5的结果将是1,7%5的结果将是2,以此类推 您可以检查a%b==0,以确定是,a可被b整除 我看不出你的问题与你发布的代码有什么关系,列表在哪里?请把你的问题贴出来。不完全是我要问的,但是谢谢。我试图找出两个

我有个问题。我想知道是否有一种方法可以只输出整数和浮点数列表中的整数

这就是我到目前为止所写的:(对它的格式感到抱歉)


我不希望它显示长小数,只显示整数。我想你想问的是,“我如何确定一个数字是否可以被另一个数字平均整除?”

这个问题的答案是

模运算基本上返回两个数除后的整数余数。因此,
6%5
的结果将是1,
7%5
的结果将是2,以此类推


您可以检查a%b==0,以确定是,a可被b整除

我看不出你的问题与你发布的代码有什么关系,列表在哪里?请把你的问题贴出来。不完全是我要问的,但是谢谢。我试图找出两个数字之间的共同点。不过,我确实说错了。我只想要整数,它给了我很多小数。关于如何实现这一点,您有什么想法吗?请使用
%
。在计算
a=x/i
时,应首先检查
x%i==0
。因为如果是这样,当你除以
x/i
时,你会得到一个整数,否则你会得到一个小数:
15%2==0
?编号
15/2=7.5
(分数结果)
# Greet the user
print("Welcome to the Common Divisors Machine!")

# Initialize variable
confirm = 'yes'

# Start nested checking against variable to start or not
while confirm != ('n' or 'N' or 'no' or 'No'):
    x = int(input("Please enter the first number: "))

    # Validating the variable "x"
    while x <= 0:
        x = int(input("Error, please enter a positive, non-zero number: "))
    # Initializing for the first part of the FOR loop
    i = 1
    y = int(input("Please enter the second number: "))

    # Validating the variable "y"
    while y <= 0:
        y = int(input("Error, please enter a positive, non-zero number: "))
    # Initializing variable for the second part of the FOR loop
    h = 1
    print("The common divisors, excluding 1 and 2, are: ")
    # Starting the FOR loop
    # Setting the variable initialized earlier to be used against "x"
    for i in range (1, x - 1):
        # Nested the second part to run within the first part
        for h in range (1, y - 1):
            # Dividing the user input
            a = x / i
            b = y / h

            # Nesting a WHILE loop to run within both of the FOR loops
            # to print the output of both
            # Also checking whether the answers are the same
            while a == b and a != 1 and a != 2:
                # Printing the output
                print(b)
                # Re initializing "a" so that it will loop back to the top
                a = 0

    # Checking whether or not the user would like to check for more divisors
    confirm = input("Would you like to continue(y/n)? ")
 # Exiting comment
print("Thank you for using the Common Divisors Machine!")
Welcome to the Common Diviors Machine!
Please enter the first number: 150
Please enter the second number: 300
The common divisors, excluding 1 and 2, are: 
150.0
75.0
50.0
37.5
30.0
25.0
21.428571428571427
18.75
16.666666666666668
15.0
13.636363636363637
12.5
11.538461538461538
10.714285714285714
10.0
9.375
8.823529411764707
8.333333333333334
7.894736842105263
7.5
7.142857142857143
6.818181818181818
6.521739130434782
6.25
6.0
5.769230769230769
5.555555555555555
5.357142857142857
5.172413793103448
5.0
4.838709677419355
4.6875
4.545454545454546
4.411764705882353
4.285714285714286
4.166666666666667
4.054054054054054
3.9473684210526314
3.8461538461538463
3.75
3.658536585365854
3.5714285714285716
3.488372093023256
3.409090909090909
3.3333333333333335
3.260869565217391
3.1914893617021276
3.125
3.061224489795918
3.0
Would you like to continue(y/n)?