Question 5

Code for Pangram Checking

Pangram Checking

Given a string check if it is Pangram or not. A pangram is a sentence containing every letter in the English Alphabet.

Examples : The quick brown fox jumps over the lazy dog ” is a Pangram [Contains all the characters from ‘a’ to ‘z’]
“The quick brown fox jumps over the dog” is not a Pangram [Doesn’t contains all the characters from ‘a’ to ‘z’, as ‘l’, ‘z’, ‘y’ are missing]

We create a mark[] array of Boolean type. We iterate through all the characters of our string and whenever we see a character we mark it. Lowercase and Uppercase are considered the same. So ‘A’ and ‘a’ are marked in index 0 and similarly ‘Z’ and ‘z’ are marked in index 25.

After iterating through all the characters we check whether all the characters are marked or not. If not then return false as this is not a pangram else return true.

Code for checking whether a string is Pangram or not

46 comments on “Question 5”


  • krish

    PYTHON CODE
    k=list(input().split())
    r=(“”.join(k)).lower()
    s=set(r)
    print(len(s)==26)


  • Aniket

    li = “abcdefghijklmnopqrs”
    string = input()
    x=0
    for i in li:
    if not i in string.lower():
    x +=1

    if x==0:
    print(“String is Pangram”)
    else:
    print(“String is not Pangram”)


  • Eight

    ## Python code
    sent = “qqwertyuioplkjhgfdsazxcvbn”
    sent = sent.lower()
    sent = sent.replace(” “,””)
    sent = set(sent)
    if(len(sent) == 26):
    print(True)
    else:
    print(False)


  • afradbasha456

    JAVA AND PYTHON

    import java.util.*;
    public class Main
    {
    public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);

    int count1=0;
    /*String str[] = {“A”,”B”,”C”,”D”,”E”,”F”,”G”,”H”,”I”,”J”,”K”,”L”,”M”,”N”,”O”,”P”,”Q”,”R”,”S”,”T”,”U”,”V”,”W”,”X”,”Y”,”Z”};*/
    String str = “ABCDEFGHIJKLMNOPQRSTUVWXYZ”;
    String str1 = sc.nextLine().toUpperCase();
    for (int i=0;i<str.length();i++){
    int count=0;
    for (int j=0;j=1){
    count1 = count1+1;
    }
    }
    System.out.println(count1);
    if(count1==26){
    System.out.println(“pangram”);
    }
    else{
    System.out.println(“Not a pangram”);
    }
    }
    }

    /*************************************PYTHON**************************************/

    i_str = “ABCDEFGHIJKLMNOPQRSTUVWXYZ”
    i_str1 = input().upper()
    count1 = 0
    for i in range (len(i_str)):
    count = 0;
    for j in range (len(i_str1)):
    if(i_str[i] == i_str1[j]):
    count = count+1
    if(count>=1):
    count1 = count1+1
    print(count1)
    if(count1 == 26):
    print(“pangram”)
    else:
    print(“Not a pangram”)


  • sandeep

    PYTHON:
    inp = input(“enter the input string:”)
    inp.lower()
    l = len(inp)
    print(inp,l)
    count = 0
    alphabet =[‘aA’,’bB’,’cC’,’dD’,’eE’,’fF’,’gG’,’hH’,’iI’,’jJ’,’kK’,’lL’,’mM’,’nN’,’oO’,’pP’,’qQ’,’rR’,’sS’,’tT’,’uU’,’vV’,’wW’,’xX’,’yY’,’zZ’]
    le=len(alphabet)
    #print(len(alphabet[0]))
    for i in range(le):
    for j in range(len(alphabet[i])):
    if alphabet[i][j] in inp:
    count+=1
    print(count)
    if count==26:
    print(“The String is a Pangram”)
    else:
    print(“The String is not a Pangram”)


  • sandeep

    Different python code:
    inp = input(“enter the input string:”)
    l = len(inp)
    print(inp,l)
    count = 0
    alphabet =[‘aA’,’bB’,’cC’,’dD’,’eE’,’fF’,’gG’,’hH’,’iI’,’jJ’,’kK’,’lL’,’mM’,’nN’,’oO’,’pP’,’qQ’,’rR’,’sS’,’tT’,’uU’,’vV’,’wW’,’xX’,’yY’,’zZ’]
    le=len(alphabet)
    #print(len(alphabet[0]))
    for i in range(le):
    for j in range(len(alphabet[i])):
    if alphabet[i][j] in inp:
    count+=1
    print(count)
    if count==26:
    print(“The String is a Pangram”)
    else:
    print(“The String is not a Pangram”)


  • somarapu

    #include
    #include
    using namespace std;
    int main()
    {
    char str[200];
    int i=0, chk=0, val= 0, a[26] = {0}, sum = 0;
    gets(str);
    while(str[i]!=’\0′)
    {
    val = 0;
    if(str[i]!=’ ‘)
    {
    val = (int)tolower(str[i]) – 97;
    a[val]++;
    }
    i++;
    }
    for(int i=0; i < 26; i++)
    {
    cout << a[i] <= 1)
    sum++;
    }
    if ( sum == 26)
    cout << "Pangrams";
    else
    cout << "Not Pangrams";
    cout<<endl;
    return 0;
    }


  • RAIHAN

    str = input().lower()
    l = list(‘abcdefghijklmnopqrstuvwxyz”) or
    import string
    l = list(string.ascii_lowercase)
    c=0
    for each in l:
    if each in str:
    c+=1
    if c==26:
    print(‘Pangram’)
    else:
    print(‘Not Pangram’)


  • Joyan

    PYTHON code
    from string import ascii_lowercase

    def pangram(s):
    if (set(ascii_lowercase).issubset(s)):
    return print(‘This is a pangram’)
    else:
    return print(‘This is not a pangram’)
    s = input()
    s = s.lower()
    pangram(s)


  • Gourav

    str = “The quick brown fox jumps over the lazy dog”
    l=[‘a’,’b’,’c’,’d’,’e’,’f’,’g’,’h’,’i’,’j’,’k’,’l’,’m’,’n’,’o’,’p’,’q’,’r’,’s’,’t’,’u’,’v’,’w’,’x’,’y’,’z’]
    dict1={}
    dict2={}
    for ele in l:
    dict1[ele]=1
    for ele in str.lower():
    if(ele!=’ ‘):
    dict2[ele]=1
    if(dict1==dict2):
    print(‘The String is a Pangram’)
    else:
    print(‘The String is Not a Pangram’)


  • Pinaki Prasanna

    all_alphabets = [‘a’, ‘b’, ‘c’, ‘d’, ‘e’, ‘f’, ‘g’, ‘h’, ‘i’, ‘j’, ‘k’, ‘l’, ‘m’, ‘n’, ‘o’, ‘p’, ‘q’, ‘r’, ‘s’, ‘t’, ‘u’, ‘v’, ‘w’, ‘x’, ‘y’, ‘z’]

    string = input(‘Enter String: ‘)
    string_in_lower_case = string.lower().replace(” “, “”)

    def check_pangram(entered_string):
    all_alphabets_in_String = []

    for i in entered_string:
    if (i not in all_alphabets_in_String):
    all_alphabets_in_String.append(i)

    if (len(all_alphabets_in_String) == len(all_alphabets)):
    print(‘Pangram’)
    else:
    print(‘Not pangram’)

    check_pangram(entered_string=string_in_lower_case)