小编tek*_*agi的帖子

python和正则表达式


#!/usr/bin/python
import re

str = raw_input("String containing email...\t")
match = re.search(r'[\w.-]+@[\w.-]+', str)
 if match:
  print match.group()

它不是最复杂的代码,我正在寻找一种获得所有匹配的方法,如果可能的话.

python regex

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

python - 返回错误的正#

我想要做的是写一个二次方程求解器,但是当解决方案应该是-1,就像quadratic(2, 4, 2)它返回一样1

我究竟做错了什么?

#!/usr/bin/python
import math
def quadratic(a, b, c):
        #a = raw_input("What\'s your `a` value?\t")
        #b = raw_input("What\'s your `b` value?\t")
        #c = raw_input("What\'s your `c` value?\t")
        a, b, c = float(a), float(b), float(c)
        disc = (b*b)-(4*a*c)
        print "Discriminant is:\n" + str(disc)
        if disc >= 0:
                root = math.sqrt(disc)
                top1 = b + root
                top2 = b - root
                sol1 = top1/(2*a)
                sol2 = top2/(2*a)
                if sol1 != sol2:
                        print "Solution 1:\n" + …

python math module function quadratic

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

完美数字错误?

目前我有这个代码,它的工作原理.

#include <stdio.h>

int isFactor(long number1, long number2)
{
  int isitFactor = (number2 % number1 == 0)?1:0;
  return isitFactor;
}

int isPerfect(int number)
{
   int counter;
   int sum;
   for (counter = 1; counter < number; counter++) 
      if (isFactor(counter, number)) 
         sum += counter;
   return (sum == number);
}

int main()
{
   int counter = 1;
   for (counter = 1; counter <= 100; counter++)
   {
      printf("", isPerfect(counter));
      if (isPerfect(counter)) 
         printf("%d\n", counter);
   }
}
Run Code Online (Sandbox Code Playgroud)

但是,如果我在main()中使用printf取出不必要的行,则无法生成任何数字....可能的原因?!

c math debugging for-loop numbers

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

python中的前缀表示法解析

马上蝙蝠 - 不,这不是功课.

我想在python中编写前缀表示法解析器(目前用于总和)...例如

如果给出:+ 2 2它将返回:4

想法?

python math addition notation

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

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

为什么有SIGFPE?

由于某种原因,它曾经工作过.但现在我得到了一个SIGFPE .....出了什么问题?

#include "usefunc.h"

long factorial(long num) {
    if (num > 1) {
        long counter;
        long fact = 1;
        for (counter = num; counter > 0; counter--) fact *= counter;
        return fact;
    }
    else return 0;
}

long combinations(long n, long k) {
    return (factorial(n)) / (factorial(k)*factorial(n-k));
}

int main()
{
    printf("How many rows of Pascal\'s triangle should I print?\t");
    int rows = GetInteger();
    long pArray[rows][rows];
    int counter;
    int counter2;
    for (counter = 1; counter <= rows; counter++)
    {
        int …
Run Code Online (Sandbox Code Playgroud)

c signals sigfpe pascals-triangle

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

写lisp方言

你有什么建议用Python编写Lisp方言/解释器吗?我想只有几个基本的命令,比如开始set,printdefine什么的.

lisp python interpreter dialect

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

在C中从头开始编写编译器

可能重复:
如何在C中编译编译器?

我将如何从头开始编写编译器(没有FlexBisonLexYacc)?我有一种语言,我为他写了一个翻译,它有点像Forth.有点.它接受符号并使用堆栈一次解释一个符号.

我如何制作编译器?

那不是特别垃圾; 只是为了向人们展示语法和简洁性.

http://github.com/tekknolagi/StackBased

c compiler-construction forth

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

jQuery - 检查字符串是否大于4个字符

我只是有一个简单的问题,我想知道是否有人可以帮助我.

我有以下脚本,如果文本字段中没有字符,则会编写一个返回错误的脚本.

我想修改脚本,以便在少于4个字符时返回错误,但我不太清楚如何.

目前的脚本如下:

    if(!isString($.trim(iUsername.val()))){ //If username is not correct
        iUsername.siblings('.error').text('You must enter a username.');
        error = true;
    }
Run Code Online (Sandbox Code Playgroud)

javascript string error-handling jquery

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

以编程方式从`p`和`q`(RSA)生成`d`

我有两个号码p,和q.我知道我可以得到phi = (p-1)*(q-1)那个ed = 1 (mod phi)......但我不确定这是什么意思.

我写了一些Python:

p = NUM
q = NUM
e = NUM
phi = (p-1)*(q-1)
d = (1 % phi)/float(e)
Run Code Online (Sandbox Code Playgroud)

但我总是得到一个小数,并且d应该是一个整数.我究竟做错了什么?

编辑:我可能只是不了解RSA.现在,我正在看这个页面:http://www.di-mgt.com.au/rsa_alg.html

python encryption rsa public-key-encryption

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