title-img


What's Your Name? Python

You are given the firstname and lastname of a person on two different lines. Your task is to read them and print the following: Hello firstname lastname! You just delved into python. Input Format: The first line contains the first name, and the second line contains the last name. Constraints: The length of the first and last name ≤ 10. Output Format: Print the output as mentioned above.

View Solution →

Mutations Python

We have seen that lists are mutable (they can be changed), and tuples are immutable (they cannot be changed). Let's try to understand this with an example. You are given an immutable string, and you want to make changes to it. Example: >>> string = "abracadabra" You can access an index by: >>> print string[5] a What if you would like to assign a value? >>> string[5] = 'k' Traceback (most recent call last): File "<stdin>

View Solution →

Find a string Python

In this challenge, the user enters a string and a substring. You have to print the number of times that the substring occurs in the given string. String traversal will take place from left to right, not from right to left. NOTE: String letters are case-sensitive. Input Format: The first line of input contains the original string. The next line contains the substring. Constraints: 1<=len(string)<=200 Each character in the string is an ascii character. Output Format: Outp

View Solution →

String Validators Python

Python has built-in string validation methods for basic data. It can check if a string is composed of alphabetical characters, alphanumeric characters, digits, etc. str.isalnum() This method checks if all the characters of a string are alphanumeric (a-z, A-Z and 0-9). >>> print 'ab123'.isalnum() True >>> print 'ab123#'.isalnum() False str.isalpha() This method checks if all the characters of a string are alphabetical (a-z and A-Z). >>> print 'abcD'.isalpha() True >>> print 'ab

View Solution →

Text Allignment Python

In Python, a string of text can be aligned left, right and center. .ljust(width) This method returns a left aligned string of length width. >>> width = 20 >>> print 'HackerRank'.ljust(width,'-') HackerRank---------- .center(width) This method returns a centered string of length width. >>> width = 20 >>> print 'HackerRank'.center(width,'-') -----HackerRank---- - .rjust(width) This method returns a right aligned string of length width. >>> width = 20 >>> print 'Hac

View Solution →