Home » Python » Python programs

Python program capitalize the character without using a function

Capitalize the character: Here, we are going to learn how to capitalize the character without using a function in Python?
Submitted by Anuj Singh, on July 11, 2019

In this article, we will go for capitalizing the characters i.e. conversion from lowercase to uppercase without using any function. This article is based on the concept that how inbuilt function perform this task for us?

So, let's write a program to perform this task.

Key: The difference between the ASCII value of A and a is 32

Example:

    Input:
    Hello world!

    Output:
    HELLO WORLD!

Python code to capitalize the character without using a function

# Python program to capitalize the character 
# without using a function
st = input('Type a string: ')
out = ''
for n in st:
    if n not in 'abcdefghijklmnopqrstuvwqxyz':
        out = out + n
    else:
        k = ord(n)
        l = k - 32
        out = out + chr(l)
print('------->', out)    

Output

First run:
Type a string: Hello world!
-------> HELLO WORLD!

Second run:
Type a string: 12345Hello @123$#
-------> 12345HELLO @123$#

Third run:
Type a string: 82918298198291898A
-------> 82918298198291898A





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.
Learn PCB Designing: PCB DESIGNING TUTORIAL







Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.