Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/jenkins/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
python中的for语句不起作用_Python_Nonetype - Fatal编程技术网

python中的for语句不起作用

python中的for语句不起作用,python,nonetype,Python,Nonetype,试图制作一个简单的程序,将单词“supercalifragilisticexpialidocious”显示出来,并用破折号替换辅音。代码如下: message = print("supercalifragilisticexpialidocious") result_str = "" CONSONANTS = "BCDFGHJKLMNPQRSTVXZWY" print() for letter in message: if letter not in CONSONANTS:

试图制作一个简单的程序,将单词“supercalifragilisticexpialidocious”显示出来,并用破折号替换辅音。代码如下:

message = print("supercalifragilisticexpialidocious")

result_str = ""

CONSONANTS = "BCDFGHJKLMNPQRSTVXZWY"

print()

for letter in message:
    if letter not in CONSONANTS:
         result_str += letter

    else:
         result_str += "-"

print(result_str)

input("\n\nPress the enter key to exit:")
当我在模块中运行它时,它正确地打印了
“message”
,但给出了此错误,而不是打印
“result\u str”

回溯(最近一次呼叫最后一次):
文件“F:/CSC119/期末考试计划4.py”,第13行,在
对于邮件中的信函:
TypeError:“非类型”对象不可编辑

那么我的问题是什么?? 多谢各位

message = "supercalifragilisticexpialidocious"

不打印?

不能将打印语句分配给变量。您需要执行
message=text
而不是
message=print(text)

您不能将变量分配给print语句。只需保留它
message='super…'
我更改了它,现在输出结果是:
supercalifragilisticexpialidious supercalifragilisticexpialidious
辅音没有破折号你的辅音都是大写的,所以不会匹配你正在比较的小写字符?我更改了它,现在输出结果是:
supercalifragilisticexpialidocious supercalifragilisticexpialidocious
而不是第二个有破折号而不是辅音。我想出来了,需要添加小写辅音,因为它只想用破折号替换大写字母。现在工作。非常感谢。没问题,很高兴你找到了答案。我没有机会尝试,因为我正在研究自己的一个问题。