小编bob*_*rge的帖子

如何测试每个特定的数字或字符

我希望收到用户输入的5位数字,然后打印每个特定数字的内容.

例如,如果用户输入12345,我想首先打印1的特定输出,然后打印另一个输出2,等等.

我该怎么做呢?如果可能的话,我更愿意创建一个函数.

#!/usr/bin/python3

zipcode = int(raw_input("Enter a zipcode: "))

if zipcode == 1:
       print ":::||"
elif zipcode == 2:
       print "::|:|"
elif zipcode == 3:
       print "::||:"
elif zipcode == 4:
       print ":|::|"
elif zipcode == 5:
       print ":|:|:"
elif zipcode == 6:
       print ":||::"
elif zipcode == 7:
       print "|:::|"
elif zipcode == 8:
       print "|::|:"
elif zipcode == 9:
       print "|:|::"
elif zipcode == 0:
       print "||:::"
Run Code Online (Sandbox Code Playgroud)

python string if-statement input function

4
推荐指数
2
解决办法
133
查看次数

标签 统计

function ×1

if-statement ×1

input ×1

python ×1

string ×1