小编kyl*_*e k的帖子

Python中的元组Subtract语句

使用Python,我想从列表中的值减去256,如果值大于256,但我所要的输出是一个元组的格式,这是我需要帮助.

x = [85, 229, 162, 45, 280, 186, 275, 265, 252, 188, 135, 150, 351, 326, 217, 43, 301, 281, 333, 39, 246, 150, 139, 186, 195, 132, 196, 171, 307, 272, 97, 330, 271, 179, 276, 141, 151, 214, 191, 111, 261, 290, 146]

for y in x:
    if y>256:
        print y-256
    else:
        print y 
Run Code Online (Sandbox Code Playgroud)

此代码将以列表格式提供正确的输出.

python if-statement tuples list

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

fflush(stdin)ANSI C

我是ANSI C的初学者,我有一个问题,这可能是一个愚蠢的问题,我很抱歉.

#include<stdio.h>
    main()
    {
          int age;
          printf("Hello World!\n");
          printf("Please enter your age: ");
          scanf("%d", &age);
          printf("You entered %d\n", age);
          fflush(stdin);
          getchar();
    }
Run Code Online (Sandbox Code Playgroud)

这是我学习scanf功能的第二个程序.我的问题是:我知道printf,scanf,fflush,stdingetchar是在stdio.h中定义的,但只有当我使用fflush(stdin)时我必须把#include < stdio.h >,但是当使用任何其他方法时我可以删除该行#include.

c fflush

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

检查python程序是否有错误

如何在不运行python程序的情况下检查错误.我想得到错误消息,说明我的错误在哪一行.但我不想执行该程序.

python testing syntax-error static-code-analysis

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

逐行读取文件并将字符串拆分为c中的标记

我正在逐行读取文件并将字符串拆分为标记.

int main()
{
    FILE* fp;
    char  line[255];

    fp = fopen("file.txt" , "r");
    while (fgets(line, sizeof(line), fp) != NULL)
    {   
        char val1[16];
        char val2[9];

        strcpy(val1, strtok(line, ","));
        strcpy(val2, strtok(NULL, ","));

        printf("%s|%s\n", val1, val2);          
    }
}
Run Code Online (Sandbox Code Playgroud)

我的输入文件内容(file.txt)

182930101222, KLA1512
182930101223, KLA1513
182930101224, KLA1514
182930101225, KLA1515
Run Code Online (Sandbox Code Playgroud)

当我打印得到

 | KLA1512
Run Code Online (Sandbox Code Playgroud)

代替

182930101222| KLA1512
Run Code Online (Sandbox Code Playgroud)

有什么问题?

c file

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

选择文本时会出现自定义复制和粘贴菜单

我正在尝试在操作栏中创建自定义复制和粘贴菜单,但是当我在EditText区域中选择文本时,将弹出默认的复制和粘贴菜单,但是当我长按EditText区域而不是文本时,自定义菜单显示在操作栏中.如何在选择文本时显示自定义复制和粘贴菜单?

我查看了类似的问题覆盖Android中的常规粘贴上下文菜单

public class MainActivity extends Activity
{

@Override
protected void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    EditText Input = (EditText) findViewById(R.id.Input);
    Input.setOnLongClickListener(new View.OnLongClickListener() {

            @Override
            public boolean onLongClick(View p1)
            {
                // TODO: Implement this method
                startActionMode(new ActionBarCallBack());
                return false;
            }
        });
}

class ActionBarCallBack implements ActionMode.Callback
{


    @Override
    public boolean onActionItemClicked(ActionMode mode, MenuItem item)
    {           
        // TODO Auto-generated method stub
        switch(item.getItemId()) {
            case R.id.copyText:
                Toast.makeText(getApplicationContext(), "Copy", Toast.LENGTH_SHORT).show();
                return true;
            case R.id.pasteText:
                Toast.makeText(getApplicationContext(), "Paste", Toast.LENGTH_SHORT).show();
                return true;
            case R.id.cutText:
                Toast.makeText(getApplicationContext(), …
Run Code Online (Sandbox Code Playgroud)

android android-actionbar

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

程序显示为几位数

此程序计算2的平方根,但它不会将数字显示为我想要的1000位精度,而是只显示50位数.

这是程序

import math 
a=format(2.0**0.5, '.1000')   
print a
Run Code Online (Sandbox Code Playgroud)

我想知道如何编写程序来显示更多数字.

python digits

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

python质数总和

我正在制作一个 python 程序,该程序将生成一个数字的素数之和,但该程序没有给出正确的结果,请告诉我原因。

b=1
#generates a list of numbers.
while b<100:
    b=b+1
    x = 0.0
    a = 0
    d = 0
    #generates a list of numbers less than b. 
    while x<b:
        x=x+1
        #this will check for divisors. 
        if (b/x)-int(b/x) == 0.0:
            a=a+1
        if a==2:
            #if it finds a prime it will add it.
            d=d+b
print d 
Run Code Online (Sandbox Code Playgroud)

我让它成功生成了一个素数列表,但我无法添加素数。

这是我用来生成素数列表的代码。

b=1
while b<1000:
    b=b+1
    n = b
    x = 0.0
    a = 0
    while x<n:
        x=x+1
        if (n/x)-int(n/x) == 0.0:
            a=a+1
    if …
Run Code Online (Sandbox Code Playgroud)

python primes sum

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

可可获得打开窗口的数量

我正在创建一个隐藏打开窗口的简单应用程序,但我想添加一个文本框,它将告诉打开的窗口数量,我需要什么可可功能呢?有没有nswindow我可以使用的功能?

cocoa nswindow

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

得到一个太少的除数

这是一个计算数字除数的数量的程序,但它实际上比该数字的除数少一个.

#include <stdio.h>

int i = 20;
int divisor;
int total;

int main()
{
    for (divisor = 1; divisor <= i; divisor++)
    {
        if ((i % divisor == 0) && (i != divisor))
        {
            total = total++;
        }
    }
    printf("%d %d\n", i, total);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

数字20有6个除数,但程序说有5个除数.

c math counter division divider

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

错误的字符串长度

我试图得到一个字符串的长度,但我得到错误的值,它说它只有4个字符长.为什么是这样?我使用sizeof()得当吗?

#include <stdio.h>

int main(void)
{
    char *s;
    int len;

    s = "hello world";
    len = sizeof(s);
    printf("%d\n", len);
}
Run Code Online (Sandbox Code Playgroud)

c string sizeof string-length

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

使用回复字段创建通知

如何从带有回复字段的通知中获取输入.我在文档中没有找到任何内容

这是我当前的代码,我需要从用户那里得到什么回复?

#import "AppDelegate.h"

@implementation AppDelegate
@synthesize nTitle;
@synthesize nMessage;

- (IBAction)showNotification:(id)sender{
    NSUserNotification *notification = [[NSUserNotification alloc] init];
    notification.title = [nTitle stringValue];
    notification.informativeText = [nMessage stringValue];
    notification.soundName = NSUserNotificationDefaultSoundName;

    [[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification:notification];
}

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
    // Insert code here to initialize your application
    [[NSUserNotificationCenter defaultUserNotificationCenter] setDelegate:self];
}
- (BOOL)userNotificationCenter:(NSUserNotificationCenter *)center shouldPresentNotification:(NSUserNotification *)notification{
    return YES;
}

@end
Run Code Online (Sandbox Code Playgroud)

我在哪里可以找到通知中心的最新信息和文档?

cocoa input nsusernotificationcenter osx-mavericks

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