标签: raw-input

使用从Python中的raw_input收集的输入

如果我在python中执行以下操作,

string = raw_input('Enter the value')
Run Code Online (Sandbox Code Playgroud)

它会回来

输入值

等到我在提示中输入内容.

有没有办法检索/收集我在变量中输入的输入string

我想以下列方式使用输入的值:

if dict.has_key('string'):
          print dict[string]
Run Code Online (Sandbox Code Playgroud)

注意:我之前犯了使用错误,raw_string但我想说raw_input

python raw-input

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

从python中的raw_input以相反的顺序打印结果

raw_input在循环中使用时,直到键入某个字符(比如说'a'),如何在此之前以相反的顺序打印所有输入,而不将输入存储在数据结构中?

使用字符串很简单:

def foo():

    x = raw_input("Enter character: ")
    string = ""
    while not (str(x) == "a"):
        string = str(x) + "\n" + string
        x = raw_input("Enter character: ")
    print string.strip()
Run Code Online (Sandbox Code Playgroud)

但是如果没有字符串我怎么能这样做呢?

python raw-input

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

输入字符串和整数

只是一个简单的问题,因为我真的找不到解决我问题的简单方法.有没有办法获得一个意味着整数的用户输入,但是当输入一个字符串时,程序不会中断,而是显示"错误"

我一直试图通过将字符串转换为整数来解决它,反之亦然,但我经常得到"无效的文字对于int()与基础10"错误,或者当它显示"错误"时它在无限循环中这样做.

这是我的代码,只是为了帮助澄清问题

choice = input("Enter your choice: ")

while choice != 3:
    if choice == 1:
        get_songs()
        print
        main()
    elif choice == 2:
        read_songs()
        print
        main()
    else:
        print "Invalid choice"
Run Code Online (Sandbox Code Playgroud)

所以基本上我希望else操作适用于字符串以及大于3或小于1的整数.

python string integer input raw-input

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

TypeError:不能将序列乘以'float'python 2.7类型的非int

嗨,我是一个11岁的孩子,已经把python作为一种业余爱好.我正在尝试将质量转换器作为第一个项目.但由于某种原因我得到了这个错误:TypeError:不能将序列乘以'float'类型的非int

这是我的代码:

    print "please enter the amount of kilograms you want to convert",
    kilo = raw_input() 
    pounds = 2.20462

    print kilo * pounds
Run Code Online (Sandbox Code Playgroud)

python raw-input

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

用户输入的持续时间

我想知道用户输入我用 raw_input() 记录的输入需要多长时间。
即他们是否需要 1 秒或 10 秒才能在命令行上输入内容。

是否有一种既定的方法可以做到这一点,或者我是否需要发明自己的方法来做到这一点?

python time duration input raw-input

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

Python:当 raw_input 无效时重复一个函数

我希望能够确定输入是否有效。我有:

servqual = raw_input(">").lower()
while servqual != "great" or "good" or "lacking" or "poor":
    print "I didn't understand that. Please try again."
    servqual = raw_input(">").lower()
Run Code Online (Sandbox Code Playgroud)

但是,每当我在循环中运行它时,它总是假定为 True,即使我输入了有效的答案。我查看了不同的答案,但似乎没有一个在这种情况下有效。

python raw-input while-loop

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

未知字符将添加到字符串的最后一个

下面是我用C++设计的应用程序的一部分.下面的代码片段显示***作为用户输入的密码.代码在程序中的两个地方使用,一个正常,另一个在结尾处显示未知字符enterdPassword.

它在这里工作正常.输入的密码保存在文件中以供进一步使用.

if(FirstRun()){
    display_welcome_text_first_run();

    cout<<"\nEnter A Password(Max 13 character): ";
    for(i=0; i<13; i++){
        x = getch();
        if(x == '\r'){ break; }
        putchar('*');
        p[i]=x;
    }

    p[i+1]='\0';
    string pwd(p);
    ofstream o(PASSWORD_FILE,ios::binary);
    o <<pwd<<endl;
    o.close();
Run Code Online (Sandbox Code Playgroud)

这里显示了它在结尾处显示未知字符的错误enterdPassword.

bool verifyPassword(){
    string savdPassword;
    char px[20], x;
    int i;
    cout<<"Enter Your Password To Continue: ";

    for(i=0; i<13; i++){
        x = getch();
        if(x == '\r'){ break; }
        putchar('*');
        px[i] = x;
    }
    px[i+1] = '\0';

    string enterdPassword(px);

    ifstream pp(PASSWORD_FILE, ios::binary);
    pp>>savdPassword;
    pp.close();
    cout<<endl<<enterdPassword;<<" "<<savdPassword; …
Run Code Online (Sandbox Code Playgroud)

c++ string raw-input

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

Python Inline语句比正常的forloop慢

我刚才正在尝试编码比赛.

我被给予N行输入是整数,所以拿那些输入,我使用下面的代码.

arr = [int(input()) for i in xrange(N)]

# where N is a given number of Inputs
Run Code Online (Sandbox Code Playgroud)

由于这段代码,我得到了TLE(时间限制超出)错误.

但是当我将输入代码更改为以下内容时,我的代码在没有TLE的情况下被接受.

arr = []
for i in xrange(N):
    arr.append(int(raw_input()))

#where N is the given number of inputs
Run Code Online (Sandbox Code Playgroud)

有些人可以解释一下,为什么执行时间有所不同,但据我的理解,两种代码形式都必须以相同的方式完成相同的任务.

python io input raw-input python-2.7

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

3.6 中 raw_input() 的替代品是什么?

e=input('what's your name?')

print('so you %s, %s, %s.' % (e,l,x))
Run Code Online (Sandbox Code Playgroud)

我想创建一个程序,我需要在其中回答我的问题,但使用 input() 只会返回[so you , , .].

input raw-input python-3.x python-3.6

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

如果raw_input(包括)x,则打印y

a = raw_input 'type x here and see what happens'
    if a (INCLUDES) 'x'
        print 'y'
Run Code Online (Sandbox Code Playgroud)

这个INCLUDES命令是什么?这有更好的方法吗?

我是网络漫画Homestuck的粉丝,其中每个巨魔都有不同的打字方式,称为怪癖.我正在研究Python中的英语翻译器的"怪癖文本"(这里有两个不同怪癖字符IM-ing)我想让它们像普通人一样.

python include raw-input

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

如何在变量中存储输入(raw_input)以便稍后在Python 2.7.9中使用它?

我将更具体,这是我的基于文本的游戏的代码的缩短编辑位:

var = ""
Run Code Online (Sandbox Code Playgroud)

类示例:

def: example2(self):

  raw = raw_input("Enter something")
    if raw == "something":
        raw2 = raw_input("Enter something again")
        if raw2 == "something again"
            pass
Run Code Online (Sandbox Code Playgroud)

我想将raw2的输入存储在变量var中,因为我需要在我的代码中稍后输入.其实我想保存输入,所以我以后可以使用它.

python variables raw-input

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

python,请告诉我什么是错的

蟒蛇,请帮忙.我希望这段代码可以询问某人是否可以获得成绩.如果他们说是,那就打印好了!如果他们说不,那就说哦!如果他们不说是或否,我希望它打印"请输入是或否"并继续问他们,直到他们最后说是或否.这是我到目前为止,当我运行它并且不输入是或否,它垃圾邮件"请输入是或否"数百万时间

theanswer= raw_input("Are you ok with that grade?")
while theanswer:
    if theanswer == ("yes"):
        print ("good!")
        break
    elif theanswer == ("no"):
        print ("oh well")
        break
    else: 
        print "enter yes or no"
Run Code Online (Sandbox Code Playgroud)

我需要做什么才能使它工作,我一直在努力

python if-statement raw-input while-loop

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