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
我该怎么做才能解决这个问题?
此功能不起作用并引发错误.我需要更改任何参数或参数吗?
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) 如果用户将从键盘输入值,我必须设置默认值.以下是用户可以输入值的代码:
input = int(raw_input("Enter the inputs : "))
Run Code Online (Sandbox Code Playgroud)
这里的值将input在输入值后分配给变量并点击'Enter',是否有任何方法,如果我们不输入值并直接点击'Enter'键,变量将直接指定默认值,如input = 0.025.
我需要一个由重复特定字符组成的字符串.在Python控制台,如果我输入:
n = '0'*8
Run Code Online (Sandbox Code Playgroud)
然后n被赋予一个由8个零组成的字符串,这是我所期望的.
但是,如果我在Python程序(.py文件)中使用相同的程序,那么程序会因错误而中止
can't multiply sequence by non-int of type 'str'
有任何解决这个问题的方法吗 ?
input_var = input ("Press 'E' and 'Enter' to Exit: ")
NameError: name 'e' is not defined
Run Code Online (Sandbox Code Playgroud)
我使用的是Python 2.5.我怎么能克服这个错误?
在教程中,我读到input和之间存在差异raw_input.我发现他们在Python 3.0中改变了这些函数的行为.什么是新行为?
为什么在python控制台解释这个
x = input()
Run Code Online (Sandbox Code Playgroud)
发送错误,但如果我把它放在file.py并运行它,它不会?
我正在使用pycharm并尝试一些简单的东西.当我尝试使用raw_input()时,编辑器显示一个未解决的引用错误.我不确定是什么问题.谁看过这个吗?
当我进入
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的新手,我正在学习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 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 ×10
python-3.x ×3
python-2.7 ×2
user-input ×2
built-in ×1
file ×1
file-io ×1
nameerror ×1
pycharm ×1
python-2.5 ×1
python-3.5 ×1
string ×1