我是python初学者,正在学习for循环。所以请任何人告诉我这段代码出了什么问题,因为我的程序不能运行(即使在PYTHON SHELL上)
words = ['cat', 'window', 'defenestrate']
for w in words:
if len(w) > 6:
words.insert(0, w)
我正在尝试使用中用Python语言编写的比特币地址验证器:
但是这段代码给我带来了麻烦:
def decode_base58(bc, length):
n = 0
for char in bc:
n = n * 58 + digits58.index(char)
return n.to_bytes(length, 'big')
我知道n要么是整型的,要么是长整型的,但是名为to_bytes的方法也不是,所以我真的不明白这段代码是怎么工作的?
有人知道这里出了什么问题吗?是我做错了什么,还是这段代码只是写错了?欢迎所有提示!
@client.event
async def on_member_join(ctx, member : discord.member):
print(f'{time} {member} has joined {ctx.guild.name}, Server ID: {ctx.guild.id}')
with open('join-log.txt', 'a') as joinlog:
joinlog.writelines(f'{time} {member} has joined {ctx.guild.nam
我最近问了一个问题,得到了第一个答案。我正在尝试将这段代码放入python代码中。这就是我的答案,但我一直得到0作为答案。
def f(n, k, s):
ans = 0
for j in range(1, min({k,s}) + 1):
print j
if (n == 1):
if (k >= s):
ans = ans + 1
elif (k < s):
ans = ans + 0
elif
大家好,我是Python的新手,目前已经复制了以下脚本:
# filename is printer.py
import sys
for arg in sys.argv:
print arg # the zeroth element is the module name
raw_input("press any key") # a trick to keep the python console open
我正在尝试获取后跟模块名称的参数。但是运行这段代码会出现以下错误:
U:\printer.py
File "U:\printer.py
print(message.guild.member_count) # 7
print(len(message.guild.members)) # 1
for member in message.guild.members:
print(str(member)) # the bot itself
我试图让一个不和谐的频道的成员,但它只列出了机器人本身。它曾经工作,我根本没有改变代码,但它突然没有,我给了bot管理员权限,不知道出了什么问题。
下面这段简单的代码在Python 3.6中给出了一个错误(但在2.7中可以):
class XY:
pre = ''
z = [pre + a for a in ['x', 'y']]
# NameError: name 'pre' is not defined.
当我将相同的代码放在函数中而不是类中时:def XY(): ...,它可以工作。当我将列表理解放在一个常规循环中时,它也能正常工作。Python2.7使用的代码与3.6中的错误代码相同!
你知道从列表理解内部访问局部类变量有什么问题吗?
我正在尝试获取字符串中“to”一词之后的所有文本。但是我只得到了单词“‘m”之后的第一个字母..
string=str("does he like")
A=re.findall(r'^does\s([\w+\s+])',string ,re.IGNORECASE)
for tuple in A:
print tuple[0]
这段代码的输出只给出了"h",但我想要"he like“。有人能看到我的代码出了什么问题吗?可能有一种更简单的方法,但我想使用re.findall。我对python和在这个网站上的帖子还是个新手。所以放过我
我试图运行这段python代码,但我一直收到错误消息“意外缩进”。我不知道出了什么问题。间距看起来还不错。你有什么想法吗?
services = ['Service1']
for service in services:
try:
print service + '\t',
if 'notavailable' not in requests.get('some website' + service + '&username=' + u
问题是关于:确定f(X)= 2x^3 - 11.7x^2 +17.7x -5的最高实根 采用定点迭代法(三次迭代,x0 = 3) 我尝试使用python代码: import numpy as np
x= 1
for i in range(3):
x = 2*(x**3)-11.7*(x**2)+17.7*(x)-5
print(i,x) 当我运行这段代码时,答案是不正确的。我的代码出了什么问题?谢谢。
我是Python的新手,我不知道这段代码出了什么问题。除了没有打印出我的打印语句,而是我得到了这个错误,“”你最喜欢的颜色是%s“)(名字,任务,颜色) TypeError:'NoneType‘对象不可调用”这是我的代码。
name = input("What is your name?")
quest = input("What is your quest?")
color = input("What is your favorite color?")
print ("Ah, so your name is %s, your
这是我的Python代码:
[...]
proc = Popen(path, stdin=stdin, stdout=PIPE, stderr=PIPE)
result = [x for x in proc.stdout.readlines()]
result = ''.join(result);
当它是ASCII时,一切运行正常。当我在stdout中接收UTF-8文本时,结果是不可预测的。在大多数情况下,输出是损坏的。这里出了什么问题?
顺便说一下,也许这段代码应该以某种方式进行优化?
我要解决的问题是在BST的无序遍历中找到第一个出现节点。下面给出了我的代码
def Inorder_search_recursive(node,key):
if not node:
return None
InOrder_search_recursive(node.lChild)
if node.value==key:
return node
InOrder_search_recursive(node.rChild)
这段代码总是不返回,它有什么问题。当我找到一个值为k的节点时,我想我已经返回了节点。为什么python不能预先传递
我的代码在下面提供,并在这里:
var input = [];
input.push($('input'));
$(input).live('keydown', function (event) {
console.log('You have pressed a key!');
});
我希望这段代码能响应控制台中的按键操作。由于某些原因,它不会。这段代码有什么问题?(注意:我知道如何修复它,但我不知道它出了什么问题!)
我正在研究“Python for Everyone”中的一个问题,第7章。这个程序的目的是获取一个文件,并以相反的字符顺序复制该文件。这段代码列出了出现的字符,但当我使用:
reversedList = sorted(charList, key=itemgetter(1), reverse=True)
I get: IndexError: string索引超出范围。这是完整的代码:
from _operator import itemgetter
def main():
file = input("Enter the name of the file to be rever
我该怎么做呢?我试图在网站上查找,但没有结果,我需要这个工作,因为我想使用它,而不是单独运行文件,所以谁能帮我处理这段代码吗?
我要知道这里出了什么问题。
input=("input 1 for encoder and 2 for decoder: ")
if input=1 open encoder.py
if input=2 open decoder.py
编辑:这个问题是不同的,而不是重复的,因为这个问题是问如何根据用户输入运行python脚本,例如用户输入1,然后运行python脚本编码器。
if option == "1":
import en
我正在尝试找出如何使用json文件将用户列入黑名单,并检查用户id是否在该文件中。到目前为止,这是我的代码: import json
with open("ids.json", "r") as f:
ids = json.load(f)
@client.command()
async def test(ctx):
if ctx.message.author.id in ids:
await ctx.send('Unfortunately, you have been blacklisted from the bot. If y
我写了这段代码,这段代码无论如何都应该可以工作。如果你不能帮我解决这个问题,那么有没有人可以帮我在python discum库中写一些东西呢? from discord.ext import commands
import discord
bot = commands.Bot(command_prefix='!')
@bot.event
async def on_ready():
for user in bot.user.friends:
message = "This Message is sent via DM"
说到蟒蛇我是个新手..。
然而,我无法让这段代码工作。我花了很长一段时间试图找出出了什么问题,在各种书籍和问题网站上,所以我来到这里。
我的python 空闲(Python)(我正在使用的软件)每次使用use语句时都会出现语法错误.
a = str
print("What is Your name")
a = input()
b = str
print("Oh Hello " + a)
print("How Are You Feeling")
b = input()
if b == "Happy":
print("
每当我执行这段代码..。
import json, urrlib2
res = urrlib2.urlopen('http://website.com/data.json')
data = json.load(res)
for line in json.dumps(data["specific"]["data"], sort_keys=True, indent=0):
print line
每个字符都打印在新行中。我使用的是python2.7,我完全不知道出了什么问题。它不应该这样做,因为当我在for line语句之前打印数据时,我会得到