Show toolbar

2011年10月12日 星期三

Python Practice ex2

標題:Python ex2 練習
Python (main.py):
# -*- coding: utf-8 -*-
def ex2():
    name = input("Please enter a character string: ")
    print("The string capitalized is ", end="")
    for i in range(0,len(name)):
        dec = int(ord(name[i]))
        if(dec>=97 and dec<=122):
            newstr = chr(dec-32)
        elif(dec>=65 and dec<=90):
            newstr = chr(dec)
        else:
            newstr = "?"
        print(newstr,end="")
    print("\n")

ex2()
說明:
使用Python3進行基礎輸入輸出大小寫轉換練習。

沒有留言:

張貼留言