代码中有3个错误,请您帮助我找到它们,我只是一个初学者。我需要将Var中的字母附加(连接)到名称列表,这是一个列表变量。但是由于我是一个字符串,所以似乎存在问题。
namelist = []
var1 = input( "Enter the name you want to validate ").upper()
namelist.append(var1[0])
for i in var1[1:]:
for j in (namelist):
if(j>=i):
namelist.insert(i,namelist.index(j))
break
else:
i.append(namelist)
print(namelist)
预期结果:快速运行代码以重新排列名称中的字母
答案 0 :(得分:0)
首先,请为变量使用明确的名称。 您到底想使用代码实现什么?
您可以使用以下代码获取字母列表:
Bitmap bmp = BitmapFactory.DecodeFile(f);
Mat img = new Mat();
img = BitmapConverter.ToMat(bmp);
并使用以下命令将变量设置为相反:
NameList = []
Input = input("Enter the name you want to validate:\n").upper()
for Character in Input:
NameList.append(Character)
print(NameList)
答案 1 :(得分:0)
您似乎想反转字符串
有几种方法,这里有一些基本的for循环
main.js:49 Uncaught TypeError: speechEvents.off is not a function
at Object.stopped_speaking (main.js:49)
at harker.emit (hark.js:16)
at hark.js:109
输出:
namelist = []
var1 = input( "Enter the name you want to validate ").upper()
for i in range(1, len(var1) + 1):
namelist.append(var1[len(var1) - i])
print (namelist)
print ("".join(namelist))
。
Enter the name you want to validate Hello
['O', 'L', 'L', 'E', 'H']
OLLEH
输出:
namelist = ''
var1 = input( "Enter the name you want to validate ").upper()
for i in range(1, len(var1) + 1):
namelist = namelist + var1[len(var1) - i]
print (namelist)
。
Enter the name you want to validate hello
OLLEH
输出:
def reverse(text):
rev_text = ""
for char in text:
rev_text = char + rev_text
return rev_text
print (reverse("hello"))