Dec 26, 2016

Pangrams-Python

Roy wanted to increase his typing speed for programming contests. So, his friend advised him to type the sentence "The quick brown fox jumps over the lazy dog" repeatedly, because it is a pangram. (Pangrams are sentences constructed by using every letter of the alphabet at least once.)
After typing the sentence several times, Roy became bored with it. So he started to look for other pangrams.
Given a sentence , tell Roy if it is a pangram or not.
Input Format
Input consists of a string .
Constraints
Length of can contain spaces, lower case and upper case letters. Lower-case and upper-case instances of a letter are considered the same.
Output Format
Output a line containing pangram if is a pangram, otherwise output not pangram.
Sample Input
Input #1
We promptly judged antique ivory buckles for the next prize    
Input #2
We promptly judged antique ivory buckles for the prize    
Sample Output
Output #1
pangram
Output #2
not pangram
Explanation
In the first test case, the answer is pangram because the sentence contains all the letters of the English alphabet.


Python 3.0 Code:

in1=list(input())
#print(in1)
j=ord('a')
for i in range(26):
    if chr(j) in in1:
        j=j+1
        continue
    if (chr(j).upper()) in in1:
        j=j+1
        continue
    else:break;
if(i==25):
    print("pangram")
else:print("not pangram")

How to split single line input-Python


Sometimes we have to give multiple inputs in one single line separated with spaces which is a burden to the programmers. However, this problem can be easily handled in python using inbuilt python functions and attributes.
The inbuilt python function that can be used is the split () function. The output of this function is always a LIST. So we have to convert it accordingly to our use.

Explanation:
Consider I am giving some input with spaces in between them like the following
1 2 3 4 5 6
Now if I apply the split() function then it will result in the following output
['1', '2', '3', '4', '5', '6']

EXAMPLE:
         Ex:1-Only with numbers
            >>> a=input()
1 2 3 4 5 6
>>> print(a)
1 2 3 4 5 6
>>> a.split()
['1', '2', '3', '4', '5', '6']


         Ex:2-With numbers and strings
            >>> a=input()
1 2 3 Hello
>>> print(a)
1 2 3 Hello
>>> a.split()
['1', '2', '3', 'Hello']

Points:                                                                                                                                                                
-Output of spilt function is always a list.
-Each value in the list is converted into string value so need to convert them expicitly.

Dec 25, 2016

Query the names of all American cities in CITY with populations larger than 120000

Query the names of all American cities in CITY with populations larger than 120000. TheCountryCode for America is USA.
Input Format
The CITY table is described as follows:CITY.jpg
Query :
Select NAME from CITY CountryCode = 'USA' and Population > 120000;

Dec 24, 2016

Query the names of all American cities in CITY with populations larger than 100,000. The CountryCode for America is USA.

Query all columns for all American cities in CITY with populations larger than 100000. TheCountryCode for America is USA.
Input Format
The CITY table is described as follows:CITY.jpg

Query:
select * from CITY where population>100000 and COUNTRYCODE='USA';

Dec 22, 2016

String Split and Join-Python

In Python, a string can be split on a delimiter.
Example:
>>> a = "this is a string"
>>> a = a.split(" ") # a is converted to a list of strings. 
>>> print a
['this', 'is', 'a', 'string']
Joining a string is simple:
>>> a = "-".join(a)
>>> print a
this-is-a-string 
Task
You are given a string. Split the string on a " " (space) delimiter and join using a - hyphen.
Input Format
The first line contains a string consisting of space separated words.
Output Format
Print the formatted string as explained above.
Sample Input
this is a string   
Sample Output
this-is-a-string 
 
 
Python 3.0 Code:
inputsplit=input().split()
output="-".join(inputsplit)
print(output)  

sWAP cASE -Python

You are given a string . Your task is to swap cases. In other words, convert all lowercase letters to uppercase letters and vice versa.

For Example:
Www.HackerRank.com → wWW.hACKERrANK.COM 
 
Pythonist 2 → pYTHONIST 2

Input Format
A single line containing a string .
Output Format
Print the modified string .
Sample Input
HackerRank.com presents "Pythonist 2".
Sample Output
hACKERrANK.COM PRESENTS "pYTHONIST 2".
 
 
Python 3.0 Code:
 
print(input().swapcase())