练习1:输入1-127的ascii码,并输出对应字符

实现程序:

data = int(raw_input("Please input a number between 0 and 128: "))

if 0< data <128:

    ch = chr(data)

    print ch

else:

    print "Error,please input a number between 0 and 128."

运行结果:

www-hhl@wwwhhl-TM4750:~/python/wl_ex1$ python ascii-output.py

Please input a number between 0 and 128: 98

b

www-hhl@wwwhhl-TM4750:~/python/wl_ex1$ python ascii-output.py

Please input a number between 0 and 128: 345

Error,please input a number between 0 and 128.

作者备注:写的还不够完善,用户输入的如果不是0-128之间的数字,应该直接再出现输入页面,这个我还不知道怎么实现,如果你知道,欢迎留言交流。我微信号:hhlwill

你可能感兴趣的:(练习1:输入1-127的ascii码,并输出对应字符)