Python - 将while循环的值打印到列表

时间:2018-01-30 22:55:31

标签: python

我有一个python代码一直运行,直到 number_of_prints 的值达到20,而它低于20,它会一直打印来自(0,20)的随机数使用randint函数

代码:

from random import *

mylist = []
number_of_prints = 0
maximum = 20
x = randint(0,20)

while number_of_prints < maximum:
    print (x)
    x = randint(0,20)
    number_of_prints += 1

它打印20个不同的数字。如何在列表中打印这些数字? 例 设置mylist以使X中的每个数字成为整数

print mylist
>>> [1,3,4,2,6,5,8,7,9,11,10,13,12,14,16,17,19,20,18]

1 个答案:

答案 0 :(得分:0)

只需将它们附加到列表

即可
> Emailaddress   MostRecentPurchase 2ndMostRecentPurchase   totalorder
> xyz@gmail.com  1/29/2018             1/11/2018              $30

SELECT
Customers.EmailAddress,
'$'+CAST(SUM(Orders.PaymentAmount) AS VARCHAR(12)) as TotalOrdered
FROM Customers,Orders
WHERE Customers.CustomerID=Orders.CustomerID
AND Orders.OrderDate BETWEEN '01/01/2017 00:00' AND '12/31/2017 23:59'
AND Orders.OrderDate = ( SELECT MAX(Orders.OrderDate) 
               FROM Orders
               WHERE OrderDate < ( SELECT MAX(OrderDate) 
                              FROM Orders
                            )
             ) 
GROUP BY Customers.EmailAddress
ORDER BY TotalOrdered DESC