def replace_char(str): new_str="" for item in str: if(item.islower()): #item>='a' and item<='z' new_str+=item.upper() else: new_str+=item return new_str """ size=len(str) for i in range(size): if(str[i].islower()): ... """ def main(): str=input("enter string ") print("after replacement ",replace_char(str)) #str.upper() - that will do the same in one line using built-in method main()