Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/18.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
使用while的Python时间表_Python_Python 3.x_Math - Fatal编程技术网

使用while的Python时间表

使用while的Python时间表,python,python-3.x,math,Python,Python 3.x,Math,为什么在python中,times table程序不能这样工作 n = int(input("Type a number: ")) count = 10 while count < 0: print(f"{count} x {n} = {n * count}") count = count - 1 结果是或应该是,例如: 1 x 5=5 2x5=10 3x5=15 4x5=20 5x5=25 6x5=30 7 x 5=35 8x5=40 9x5=45 10 x 5=50

为什么在python中,times table程序不能这样工作

n = int(input("Type a number: "))
count = 10
while count < 0:
    print(f"{count} x {n} = {n * count}")
    count = count - 1
结果是或应该是,例如:

1 x 5=5

2x5=10

3x5=15

4x5=20

5x5=25

6x5=30

7 x 5=35

8x5=40

9x5=45

10 x 5=50

作为一个初学者,我需要理解。。。在这种情况下是否可以使用?
这是Python3.x,您需要将while中的条件设置为true才能完成循环。因此,当count大于或等于零时,我们将说do

n = int(input("Type a number: "))
count = 10
while count >= 0:
    print(f"{count} x {n} = {n * count}")
    count = count - 1
您希望从1开始计数,以便循环递增而不是递减。您的while循环条件检查也不正确,因为计数从不小于0。试试这个:

n = int(input("Type a number: "))
count = 1
while count <= 10:
    print(f"{count} x {n} = {n * count}")
    count = count + 1

这会反过来打印列表。是的,OP已经找到了那部分。答案说明了在while循环中定义条件的语法。
n = int(input("Type a number: "))
count = 1
while count <= 10:
    print(f"{count} x {n} = {n * count}")
    count = count + 1