相关疑难解决方法(0)

我如何在Python 3中使用raw_input

import sys
print(sys.platform)
print(2**100)
raw_input()
Run Code Online (Sandbox Code Playgroud)

我正在使用Python 3.1并且无法raw_input"冻结"dos弹出窗口.我正在阅读的书是Python 2.5,我使用的是Python 3.1

我该怎么做才能解决这个问题?

python python-3.x

523
推荐指数
6
解决办法
83万
查看次数

使用python创建新文本文件时出错?

此功能不起作用并引发错误.我需要更改任何参数或参数吗?

import sys

def write():
    print('Creating new text file') 

    name = input('Enter name of text file: ')+'.txt'  # Name of text file coerced with +.txt

    try:
        file = open(name,'r+')   # Trying to create a new file or open one
        file.close()

    except:
        print('Something went wrong! Can\'t tell what?')
        sys.exit(0) # quit Python

write()
Run Code Online (Sandbox Code Playgroud)

python file-io file python-3.x

69
推荐指数
3
解决办法
27万
查看次数

python中空用户输入的默认值

如果用户将从键盘输入值,我必须设置默认值.以下是用户可以输入值的代码:

input = int(raw_input("Enter the inputs : "))
Run Code Online (Sandbox Code Playgroud)

这里的值将input在输入值后分配给变量并点击'Enter',是否有任何方法,如果我们不输入值并直接点击'Enter'键,变量将直接指定默认值,如input = 0.025.

python user-input default-value

24
推荐指数
4
解决办法
5万
查看次数

将字符串与python中的数字相乘

我需要一个由重复特定字符组成的字符串.在Python控制台,如果我输入:

n = '0'*8
Run Code Online (Sandbox Code Playgroud)

然后n被赋予一个由8个零组成的字符串,这是我所期望的.

但是,如果我在Python程序(.py文件)中使用相同的程序,那么程序会因错误而中止
can't multiply sequence by non-int of type 'str'

有任何解决这个问题的方法吗 ?

python

17
推荐指数
3
解决办法
6万
查看次数

Python input()函数的NameError

input_var = input ("Press 'E' and 'Enter' to Exit: ")

NameError: name 'e' is not defined
Run Code Online (Sandbox Code Playgroud)

我使用的是Python 2.5.我怎么能克服这个错误?

python python-2.5

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

`input`和`raw_input`之间的区别

在教程中,我读到input和之间存在差异raw_input.我发现他们在Python 3.0中改变了这些函数的行为.什么是新行为?

为什么在python控制台解释这个

x = input()
Run Code Online (Sandbox Code Playgroud)

发送错误,但如果我把它放在file.py并运行它,它不会?

python

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

pycharm builtin未解析的参考

我正在使用pycharm并尝试一些简单的东西.当我尝试使用raw_input()时,编辑器显示一个未解决的引用错误.我不确定是什么问题.谁看过这个吗?

python built-in pycharm

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

如何在python 2.7中将用户输入转换为字符串

当我进入

username = str(input("Username:"))

password = str(input("Password:"))

运行程序后,我用我的名字输入输入并按回车键

username = sarang

我收到了错误

NameError: name 'sarang' is not defined

我试过了

username = '"{}"'.format(input("Username:"))

password = '"{}"'.format(input("Password:"))

但我最终得到了同样的错误.

如何将输入转换为字符串并修复错误?

python string user-input nameerror python-2.7

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

了解全局名称和Python2和3

作为Python的新手,我正在学习Python2和3之间的一些差异.在Python课程中,似乎有些事情需要在代码中进行更改以使其在3中工作.这是代码;

def clinic():
    print "In this space goes the greeting"
    print "Choose left or right"
    answer = raw_input("Type left or right and hit 'Enter'.")
    if answer == "LEFT" or answer == "Left" or answer == "left":
        print "Here is test answer if you chose Left."
    elif answer == "RIGHT" or answer == "Right" or answer == "right":
        print "Here is the test answer if you chose Right!"
    else:
        print "You didn't make a valid choice, please try again."
        clinic()

clinic() …
Run Code Online (Sandbox Code Playgroud)

python python-2.7 python-3.x

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

无法将字符串转换为int

我目前开始使用python 2中的python 3.在Python 2中,字符串类型转换可以使用int()函数轻松完成,但我在Py3.5.3中遇到问题

current = input("Enter the Current price: ")
int(current)
print (type(current))
c = current - 24
Run Code Online (Sandbox Code Playgroud)

Class str即使在类型转换功能之后,电流仍然显示为.

错误是 TypeError: unsupported operand type(s) for -: 'str' and 'int'

我知道这只是一个小错误,但我在网上查看的例子都使用了我使用的int函数.这可能是什么问题

python python-3.5

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