【发布时间】:2016-12-28 21:14:13
【问题描述】:
大家好,我正在学习 python,我有这个问题,因为没有创建 1000 个“if”函数,我会这样做:
#Vari flag
print "choose flag"
print "(1) Syn"
print "(2) Ack"
print "(3) Push"
print "(4) Fin"
print "(5) Urg"
print "(6) Rst"
flag-list = ["--syn","--ack","--push","--fin","--urg","--rst"]
flag = raw_input(write number separated by comma: )
现在我将把写入的数字转换为“标志列表”的文本。
【问题讨论】:
-
你的意思是
flag-list[int(flag) - 1]吗? -
您好,欢迎来到 StackOverflow。请花一些时间阅读帮助页面,尤其是名为"What topics can I ask about here?" 和"What types of questions should I avoid asking?" 的部分。更重要的是,请阅读the Stack Overflow question checklist。您可能还想了解Minimal, Complete, and Verifiable Examples。
-
flag-list无效,不允许在变量名中使用连字符,请尝试flag_list。raw_input()中的提示周围没有引号。raw_input()返回一个字符串,要将其用作索引值,您需要将该值转换为int()。
标签: python