Wednesday, February 1, 2017

User Defined String Upper Function Python

Tags

Following code defines a function upper which changes the entered string to Upper Case:

Code::

def upper(a):
    x=""                                                 #for returning Upper Case
    for i in a:
        if(i>='a'):                                     #for Not Changing Already upper Case Letters
            x=x+((chr((ord(i)-32))))
        else:
            x=x+i
    return x

i=input("Enter any String :")
print(upper(i))

Output::