Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/341.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_Python_Random - Fatal编程技术网

赌场-随机运气-Python

赌场-随机运气-Python,python,random,Python,Random,对不起我的英语。我每个月去赌场玩一次,一个月一次。我的决定标准:使用随机模块查找在赌场玩的日期和星期,只有一个例外,不接受随机模块上个月玩的日期和星期。例如,如果我去了10月14日,11月的那一天应该是任何一天,但不是14日。这是我的代码:例如,如果我输入了相同的数字“2”,程序不会删除我上个月的数字“2”。请帮忙 import random zz = raw_input ("Please enter the last week number: ") fx = int(zz) print

对不起我的英语。我每个月去赌场玩一次,一个月一次。我的决定标准:使用随机模块查找在赌场玩的日期和星期,只有一个例外,不接受随机模块上个月玩的日期和星期。例如,如果我去了10月14日,11月的那一天应该是任何一天,但不是14日。这是我的代码:例如,如果我输入了相同的数字“2”,程序不会删除我上个月的数字“2”。请帮忙

import random

zz = raw_input ("Please enter the last week number: ")

fx = int(zz)

print fx



week_randoms=[]

gg = week_randoms


for i in range (4):

    gg = week_randoms

    gg.append(random.randrange(1,5))

print gg

hh = gg[0:1]


if fx != hh:

    print "You got your number baby", hh

else:
    print  "Run this program again"

试试这个,它会给你未来12个月的日期。 它将排除29-31天,所以我们没有任何想象中的日子,比如2月31日

import random
days = range(1,29)
months = ['January','February','March','April','May','June','July','August','September','October','November','December']
for a in months:
    b = random.choice(days)
    days.remove(b)
    print "Go on Day " + str(b) + " of the month of " + a " "."

您只需记录最后一天选择的号码,并确保不再选择。今年(或任何其他闰年):

e、 g


祝你好运

略为修改的s实施版本:

import calendar
import random

last_pick = None

for i in range(1, 13):
    month = calendar.month_name[i]
    _, end = calendar.monthrange(2016, i)

    while True:
        day = random.randint(1, end)

        if day != last_pick:
            break

    last_pick = day

    print(day, month, 2016)

二月,除了闰年还有28天!
28 January 2016
22 February 2016
21 March 2016
13 April 2016
21 May 2016
24 June 2016
25 July 2016
9 August 2016
16 September 2016
12 October 2016
5 November 2016
7 December 2016
import calendar
import random

last_pick = None

for i in range(1, 13):
    month = calendar.month_name[i]
    _, end = calendar.monthrange(2016, i)

    while True:
        day = random.randint(1, end)

        if day != last_pick:
            break

    last_pick = day

    print(day, month, 2016)