如何将python计数为用户给出的整数?

时间:2017-10-26 18:28:50

标签: python integer

import time
zero = 0
eight = 8
nine = 9
ten = 10
twelve = 12
nineteen = 19
twenty = 20
while zero <= ten:
    print(zero)
    zero += 1
    time.sleep(0)
while twelve <= twenty:
    print(twelve)
    twelve += 2
    time.sleep(0)
while nineteen >= ten:
    print(nineteen)
    nineteen -= 1
    time.sleep(0)
while eight >= 0:
    print(eight)
    eight -= 2
    time.sleep(0)
**x = int(input("What number would you like to count to?: "))
while zero >= x:
        print(zero)
        zero += 2
        time.sleep(1)**

一切正常,直到粗体部分,我希望python计数到用户给出的数字(从零到X),间隔为2.对不起,如果这个问题太简单了问我但是我是编码相当新,我找不到任何答案,所以我决定在这里发帖。

3 个答案:

答案 0 :(得分:0)

你的情况是倒退的:
在请求输入之前重置''' chebyshev5_batch Purpose: perform the graph filtering on the given layer Args: x: the batch of inputs for the given layer, dense tensor, size: [N, M, Fin], L: the batch of sorted Laplacian of the given layer (tf.Tensor) if in dense format, size of [N, M, M] Fout: the number of output features on the given layer K: the filter size or number of hopes on the given layer. lyr_num: the idx of the original Laplacian lyr (start form 0) Output: y: the filtered output from the given layer ''' def chebyshev5_batch(x, L, Fout, K, lyr_num): N, M, Fin = x.get_shape() #N, M, Fin = int(N), int(M), int(Fin) # # Rescale Laplacian and store as a TF sparse tensor. Copy to not modify the shared L. # L = scipy.sparse.csr_matrix(L) # L = graph.rescale_L(L, lmax=2) # L = L.tocoo() # indices = np.column_stack((L.row, L.col)) # L = tf.SparseTensor(indices, L.data, L.shape) # L = tf.sparse_reorder(L) # # Transform to Chebyshev basis # x0 = tf.transpose(x, perm=[1, 2, 0]) # M x Fin x N # x0 = tf.reshape(x0, [M, Fin*N]) # M x Fin*N def expand_concat(orig, new): new = tf.expand_dims(new, 0) # 1 x N x M x Fin return tf.concat([orig, new], axis=0) # (shape(x)[0] + 1) x N x M x Fin # L: # N x M x M # x0: # N x M x Fin # L*x0: # N x M x Fin x0 = x # N x M x Fin stk_x = tf.expand_dims(x0, axis=0) # 1 x N x M x Fin (eventually K x N x M x Fin, if K>1) if K > 1: x1 = tf.matmul(L, x0) # N x M x Fin stk_x = expand_concat(stk_x, x1) for kk in range(2, K): x2 = tf.matmul(L, x1) - x0 # N x M x Fin stk_x = expand_concat(stk_x, x2) x0 = x1 x1 = x2 # now stk_x has the shape of K x N x M x Fin # transpose to the shape of N x M x Fin x K ## source positions 1 2 3 0 stk_x_transp = tf.transpose(stk_x, perm=[1,2,3,0]) stk_x_forMul = tf.reshape(stk_x_transp, [N*M, Fin*K]) #W = self._weight_variable([Fin*K, Fout], regularization=False) W_initial = tf.truncated_normal_initializer(0, 0.1) W = tf.get_variable('weights_L_'+str(lyr_num), [Fin*K, Fout], tf.float32, initializer=W_initial) tf.summary.histogram(W.op.name, W) y = tf.matmul(stk_x_forMul, W) y = tf.reshape(y, [N, M, Fout]) return y

zero

并更改

zero = 0
x = int(input("What.........

while zero >= x:

答案 1 :(得分:0)

如果您执行以下操作,我会说您可以同时避免使用rangewhile

print(2 * (x // 2))

答案 2 :(得分:0)

要完成计数到用户以2为间隔给出的数字的任务,你可以这样做:

list1 = []
num = int(input("Enter a number: ")) 

for i in range(num + 1):
    list1.append(i) 

print(list1[::2])

我希望我解决了你的问题。