samedi 18 avril 2015

How to test each specific digit or character

I would like to receive 5 digits from the user input and then print something for each specific digit. For example if the user enters 12345, then I would like to print the output for 1 first, then the output for 2, etc. How would I go about doing this? I would prefer to create a function if possible.



#!/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 "||:::"

Aucun commentaire:

Enregistrer un commentaire