小编And*_*den的帖子

Python-Challenge Level 3

问题是:一个小写字母,每边都有三个大保镖.我写了这段代码并得到答案.我认为这是正确的,但它不起作用.有谁能够帮我?我的回答:KWGtIDC

import urllib, sys, string
from string import maketrans

bbb = 0

f = urllib.urlopen("http://www.pythonchallenge.com/pc/def/equality.html")
while 1:
    buf = f.read(200000)
    if not len(buf):
        break
    for x in range(len(buf)):
        if buf[x] in string.ascii_lowercase:
           if buf[x+1] in string.ascii_uppercase:
               if buf[x-1] in string.ascii_uppercase:
                   if buf[x+2] in string.ascii_uppercase:
                       if buf[x-2] in string.ascii_uppercase:
                           if buf[x+3] in string.ascii_uppercase:
                               if buf[x-3] in string.ascii_uppercase:
                                   if buf[x+4] in string.ascii_lowercase:
                                       if buf[x-4] in string.ascii_lowercase:
                                           bbb = x
    sys.stdout.write(buf)
    print(buf[bbb-3:bbb+4])
Run Code Online (Sandbox Code Playgroud)

python

1
推荐指数
1
解决办法
6207
查看次数

使用Java同步的多线程安全性

我正在实施一个计算Julia集的程序.它将使用多个线程,具体取决于可用的处理器数量.每个线程计算一条线,但仅当该线未由另一个线程计算时.这部分工作得很好.

但有时当我用更大的图像测试它时(更多的线来计算,例如,而不是getHeight() = 1200,我设置它3000,有一些线被跳过).我想让它更安全,因此不会计算任何行两次,也不会跳过任何行.这是run()方法的代码:

 public void run() {
     while (counter < getHeight()-1) {  
         synchronized(this) {
             if (counter >= getHeight() -1) { //so that the last line will not be calculated >2 times.
                 return;
             }
             counter++;
             image.setRGB(0, counter, getWidth(), 1, renderLine(counter), 0, 0);
         }
     }
  }
Run Code Online (Sandbox Code Playgroud)

我想让它像这样工作:如果正在计算当前行,则线程转到下一行..没有它会混淆,所以行被跳过..

我正在尝试这个:

 public void run() {
     while (counter < getHeight()-1 && !working) {  
         synchronized(this) {
             working = true;
             if (counter >= getHeight() -1) { //so that the last line …
Run Code Online (Sandbox Code Playgroud)

java multithreading synchronized thread-safety

1
推荐指数
1
解决办法
603
查看次数

1
推荐指数
1
解决办法
426
查看次数

填写程序

Python的随机模块中的randint(a,b)函数返回a到b范围内的"随机"整数,包括两个端点.填写下面函数中的空白,该空白创建并返回0和1的长度为n的随机字符串.

from random import randint:
def randString01(n):
    _________________
    _________________
    for count in range(n):
        __________________
    return________________
Run Code Online (Sandbox Code Playgroud)

(编辑::导入语句的末尾不属于;但是,如原始问题中所示.)

...到目前为止,我发现如何将n变成n长度的字符串(所以n n的字符串)我想知道randint适用于哪里?到目前为止我有

from random import randint
def randString01(num): 
    x = str() 
    count = num 
    while count >0: 
        if randint(0,1) == 0: 
            append.x(0)   
        else: 
            append.x(1) 
        count -= 1
    x=str(x) 
    return x
Run Code Online (Sandbox Code Playgroud)

但它不起作用.我该怎么办?

python

0
推荐指数
1
解决办法
349
查看次数

Python编程作业

首先,谢谢你的时间和答案.我的任务是让我的程序打开一个文本文件,读取它的数据,这样每个单词都是一个不同的字符串,并创建一个HTML文档,将每个字符串显示为随机颜色.因此,它几乎要求我们从文本文件中取出每个单词,将每个单词更改为随机颜色,并从中创建HTML文档.这是我到目前为止的代码:

import random  
def main():
    filename = input("Enter Text File:") 
    infile = open(filename, "r")
    filename2 = input("Enter HTML Document:")
    outfile = open(filename2, "w")
    print("<html>", file=outfile)
    print("  <head>", file=outfile)
    print("  </head>", file=outfile)
    print("  <body>", file=outfile)
    filestring = infile.read()
    file = filestring.split()
    filelength = len(file)
    num = int(random.uniform(0,256))
    num1 = int(random.uniform(0,256))
    num2 = int(random.uniform(0,256))
    i = 0


    for i in range(filelength):
        r = num
        g = num1
        b = num2
        rgb = "{0:02X}{1:02X}{2:02X}".format(r, g, b)
        print('    <span style="color:#{0}">{1}</span>'.format(rgb,                    file[i]),file=outfile)
        i = 0 …
Run Code Online (Sandbox Code Playgroud)

html python file-io

0
推荐指数
1
解决办法
254
查看次数

我的Python方程求解器无法求解分数

好的,所以我制作了一个小方程求解器来求解x.它适用于整数值,但每当我尝试求解分数时,它就会进入无限循环.这是我的代码:

print "Make the variable in your equation stand for x"
print
startingLimit=int(raw_input("What is the lowest estimate that your variable could possibly be?"))
print
wholeNumber=raw_input("Do you know if your variable will be a whole number or a fraction? Answer: yes/no")
if (wholeNumber== "yes"):
    print
    fraction= raw_input("Is it a decimal/fraction? Answer:yes/no")
    if (fraction=="yes"):
        print
        print "This program will only calculate up to the 2nd place to the right of the decimal"
        xfinder=float(0.01)
    else:
        xfinder=int(1)
else:
    xfinder=float(0.01)


leftEquation=raw_input("Enter your left side of …
Run Code Online (Sandbox Code Playgroud)

python integer loops equation

0
推荐指数
1
解决办法
205
查看次数

组合DataFrame中的行

我有一个DataFrame18列和大约10000行的熊猫.

我的第一个3列有不同的值YEAR,MONTHDAY.我需要合并这三列,并将所有行的整个日期放在一列中.

到目前为止我的代码是:

df.merge('Year','/','Month')
Run Code Online (Sandbox Code Playgroud)

python numpy python-2.7 python-3.x pandas

0
推荐指数
1
解决办法
2054
查看次数

嵌套循环C#上出现内存不足错误

我看了这个,我几乎得到了它,但我有一个剩余的运行时错误.
我的代码如下:

while ((line = reader.ReadLine()) != null)
{
    while (reader.Peek() != '\r')
    {
        datalinestream.Add(GetWord(reader));
    }
    LuceneDB.AddUpdateLuceneIndex(new MATS_Doc( datalinestream));
    datalinestream.Clear();
}
Run Code Online (Sandbox Code Playgroud)

代码正在导入数据,但循环不会中断,并且由于以下原因而崩溃

"mscorlib.dll中发生了'System.OutOfMemoryException'类型的未处理异常"

外部while循环的适当中断条件是什么,以确保我读取整个文件并在结束时中断.我很难解决这个问题,因为我需要前进到下一行,我需要跳过电子表格中的第一行.任何帮助非常感谢.

*更新*

我清除字符串列表,因为我正在为lucene索引创建一个文档,它只有大约14个字段,我不希望列表变得太大.

我的getword代码

private string GetWord(TextReader inputdata)
        {
            String word = "";

            while (inputdata.Peek() >= 0)
            {
                word += (char)inputdata.Read();
                if ((word.Contains(";"))) break;
            }

        return word;
    }
Run Code Online (Sandbox Code Playgroud)

c# streamreader while-loop

0
推荐指数
1
解决办法
317
查看次数

基本异常处理

我正在尝试执行这个简单的exceptiion处理程序,但由于某种原因它不起作用.我希望它抛出异常并将错误写入文件.

fileo = "C:/Users/bgbesase/Documents/Brent/ParsePractice/out.txt"

g = 4
h = 6
try:
    if g > h:
        print 'Hey'
except Exception as e:
    f = open(fileo, 'w')
    f.truncate()
    f.write(e)
    f.close()
    print e
Run Code Online (Sandbox Code Playgroud)

我有什么想法我做错了吗?

python exception

0
推荐指数
1
解决办法
122
查看次数

加入2个列表,Python

如何将2个列表与元素并排加入?例如:

list1 = ["they" , "are" ,"really" , "angry"]  
list2 = ["they" , "are" ,"seriously" , "angry"] 
Run Code Online (Sandbox Code Playgroud)

我希望输出为:

list3 = [("they","they"),("are","are"),("really","seriously"),("angry","angry")]
Run Code Online (Sandbox Code Playgroud)

上面看起来像一个列表元组,如果上面的列表是连续每个单词的列,我如何将list2追加到list1?

python list

-2
推荐指数
1
解决办法
294
查看次数

Filemaker:从门户网站转到相关记录

我有一个门户网站,我想点击其中一个项目来切换布局并查看与点击项目相关的记录.

我怎么样?

filemaker

-4
推荐指数
1
解决办法
7322
查看次数