在下面的代码中为什么x和y字符串而不是整数?网上的所有内容都说要使用raw_input(),但是我读input()了raw_input()在Python 3.x中重命名的Stack Overflow(在一个不处理整数输入的线程上).
play = True
while play:
x = input("Enter a number: ")
y = input("Enter a number: ")
print(x + y)
print(x - y)
print(x * y)
print(x / y)
print(x % y)
if input("Play again? ") == "no":
play = False
Run Code Online (Sandbox Code Playgroud) 是否有任何简短的方法来实现APT(高级软件包工具)命令行界面在Python中的作用?
我的意思是,当包管理器提示后面是/否问题时[Yes/no],脚本接受YES/Y/yes/y或Enter(默认Yes为大写字母暗示).
我在官方文档找到的唯一的事情就是input和raw_input...
我知道这并不难以模仿,但重写是很烦人的:|
在过去的几天里,我一直在玩Numpy和matplotlib.我在尝试使matplotlib绘制函数而不阻塞执行时遇到问题.我知道在这里已经有很多线索提出了类似的问题,而且我已经搜索了很多但是没有设法让这项工作成功.
我曾经尝试过使用show(block = False),但我得到的只是一个冻结的窗口.如果我只是调用show(),则会正确绘制结果,但会阻止执行直到窗口关闭.从我读过的其他主题,我怀疑show(block = False)是否有效取决于后端.它是否正确?我的后端是Qt4Agg.你能看看我的代码并告诉我你是否看错了吗?这是我的代码.谢谢你的帮助.
from math import *
from matplotlib import pyplot as plt
print plt.get_backend()
def main():
x = range(-50, 51, 1)
for pow in range(1,5): # plot x^1, x^2, ..., x^4
y = [Xi**pow for Xi in x]
print y
plt.plot(x, y)
plt.draw()
#plt.show() #this plots correctly, but blocks execution.
plt.show(block=False) #this creates an empty frozen window.
_ = raw_input("Press [enter] to continue.")
if __name__ == '__main__':
main()
Run Code Online (Sandbox Code Playgroud)
PS.我忘了说我想在每次绘制内容时更新现有窗口,而不是创建一个新窗口.
我完全迷失了为什么这不起作用.应该准确地工作吧?
UserName = input("Please enter your name: ")
print ("Hello Mr. " + UserName)
raw_input("<Press Enter to quit.>")
Run Code Online (Sandbox Code Playgroud)
我得到这个例外:
Traceback (most recent call last):
File "Test1.py", line 1, in <module>
UserName = input("Please enter your name: ")
File "<string>", line 1, in <module>
NameError: name 'k' is not defined
Run Code Online (Sandbox Code Playgroud)
它说NameError 'k',因为我'k'在测试期间写了输入.我已经读过print语句曾经没有括号但是已被弃用了吗?
我正在学习python并且有这个错误.我可以弄清楚代码中的错误是什么.
File "<string>", line 1, in <module>.
Name = ""
Desc = ""
Gender = ""
Race = ""
# Prompt user for user-defined information
Name = input('What is your Name? ')
Desc = input('Describe yourself: ')
Run Code Online (Sandbox Code Playgroud)
当我运行该程序
它输出你的名字是什么?(我输入d)
这给出了错误
Traceback (most recent call last):
File "/python/chargen.py", line 19, in <module>
Name = input('What is your Name? ')
File "<string>", line 1, in <module>
NameError: name 'd' is not defined
Run Code Online (Sandbox Code Playgroud)
这是Python 3 for Absolute Beginners的示例代码.
我有字符串变量测试,在Python 2.7中这很好用.
test = raw_input("enter the test")
print test
Run Code Online (Sandbox Code Playgroud)
但是在Python 3.3中.我用
test = input("enter the test")
print test
Run Code Online (Sandbox Code Playgroud)
使用输入字符串test,我收到一条错误消息
Traceback(最近一次调用最后一次):
文件"/home/ananiev/PycharmProjects/PigLatin/main.py",
第5行,在test = input("输入测试")
NameError中的文件"",第1行:名称'sdas'未定义
好的,所以我在python中编写成绩检查代码,我的代码是:
unit3Done = str(input("Have you done your Unit 3 Controlled Assessment? (Type y or n): ")).lower()
if unit3Done == "y":
pass
elif unit3Done == "n":
print "Sorry. You must have done at least one unit to calculate what you need for an A*"
else:
print "Sorry. That's not a valid answer."
Run Code Online (Sandbox Code Playgroud)
当我通过我的python编译器运行它并且我选择时"n",我得到一个错误说:
"NameError:名称'n'未定义"
当我选择"y"我再NameError有'y'是问题,但是当我做别的事情,代码运行正常.
任何帮助是极大的赞赏,
谢谢.
我执行此代码时出错:
nameUser=input("What is your name ? ")
print (nameUser)
Run Code Online (Sandbox Code Playgroud)
错误消息是
回溯(最近一次调用最后一次):文件"C:/Users/DALY/Desktop/premier.py",第1行,在文件"",第1行,在NameError中:名称'klj'未定义
这是怎么回事?
这很奇怪,因为我的代码在在线 python 解释器中运行良好,但是当我在带有 Atom 的 linux mint 中运行它时,当我输入一个单词时出现此错误消息:
File "<string>", line 1, in <module>
NameError: name 'lol' is not defined
Run Code Online (Sandbox Code Playgroud)
这是我的代码
# -*- coding: utf-8 -*-
word = str(input(" Enter a word : "))
reverse = word[::-1]
if reverse == word:
print("it is a palindrome, félicitation : ")
else:
print(" it is not a palindrome : ")
Run Code Online (Sandbox Code Playgroud) 我想使用python将几个.csv文件转换为.txt文件.在我的.csv文件中,我有数百行数据,如下图: csv文件的图像
Value Date Time
919 4/15/2016 19:41:02
551 4/15/2016 19:46:51
717 4/15/2016 19:49:48
2679 4/15/2016 19:52:49
2890 4/15/2016 19:55:43
2897 4/15/2016 19:58:38
1790 4/15/2016 21:39:14
2953 4/15/2016 21:42:10
2516 4/15/2016 21:45:04
2530 4/15/2016 21:47:58
2951 4/15/2016 21:51:02
2954 4/15/2016 21:53:56
2537 4/15/2016 21:56:52
2523 4/15/2016 21:59:45
2536 4/15/2016 22:02:49
2727 4/15/2016 22:05:43
Run Code Online (Sandbox Code Playgroud)
我为此目的使用波纹管代码.
csv_file = input('Enter the name of your input file: ')
txt_file = input('Enter the name of your output file: ')
text_list = []
with open(csv_file, "r") …Run Code Online (Sandbox Code Playgroud) python ×10
python-3.x ×4
input ×2
python-2.7 ×2
atom-editor ×1
csv ×1
eval ×1
int ×1
matplotlib ×1
nameerror ×1
plot ×1
string ×1
terminal ×1
text ×1