Bermain String dengan Python


import sys

pgun='''penggunaan: %s <kalimat>
contoh: python %s saya pusing'''%(sys.argv[0],sys.argv[0])

def main():
args = sys.argv[1:]
if len(sys.argv) <= 1:
print pgun

 #reverse kata (dalam bentuk list)

 #tampilkan kata yang sudah di reverse (dalam bentuk list)
 print "Hasil Reverse kalimat:n======================="
 print args,"n"

 #join isi list dan tampilkan
 print "Hasil Join kalimat:n======================="
 teks = ' '.join(args)
 print teks,"n"

 #reverse perhuruf dan tampilkan
 print "Hasil Reverse perhuruf:n======================="
 print ''.join(reversed(teks))

if __name__ == '__main__':

in action:

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

About Hanny Haliwela

try to be or not try to be