Monday, January 30, 2017

PygLatin Python :)

Pig Latin is a language game, where you move the first letter of the word to the end and add "ay." So "Computer" becomes "omputercay." 

Following are the Steps involved:
1.Input the word
2. Converting the String to Lowercase
3. Assign first letter of the word to another variable
4. Removing first letter from the word
5. Concatenating the Strings for Output
Following Program Illustrates it:

word=input("Enter the Word: ")   #input word
temp=word.lower()   #lowercase conversion
first=temp[0]       #first letter
temp=temp[1:]
suffix='ay'
if(len(word)==0):
    print("String is Empty!!")
elif word.isalpha()==False:  #else if statement
    print("Enter only Alphabets!")
else:
    print("Pig Latin translation of "+word+" is ")
    print(temp+first+suffix)



Note: isalpha() function is used to check whether String contains alphabets or not. It gives True when all letters in String are alphabets.

"99 Bottles of Beer"

Question::
"99 Bottles of Beer" is a traditional song in the United States and Canada. It is popular to sing on long trips, as it has a very repetitive format which is easy to memorize, and can take a long time to sing. The song's simple lyrics are as follows:
99 bottles of beer on the wall, 99 bottles of beer.
Take one down, pass it around, 98 bottles of beer on the wall.
The same verse is repeated, each time with one fewer bottle. The song is completed when the singer or singers reach zero.
Your task here is write a Python program capable of generating all the verses of the song.


Code::
l=99
for l in (range(99,1,-1)):

    print(l ,"bottles of beer on the wall," ,l," bottles of beer.\nTake one down, pass it around,",l-1 ,"bottles of beer on the wall.\n")


Output::

Pangram Python

Question::
pangram is a sentence that contains all the letters of the English alphabet at least once, for example: The quick brown fox jumps over the lazy dog. Your task here is to write a function to check a sentence to see if it is a pangram or not.

Code::

def panagram(nt):
    check="abcdefghijklmnopqrstuvwxyz"
    for l in check:
        if(l in nt):
            continue
        else:
            return False
    return True           
n=input("Enter Any Text:")
if(panagram(n.lower())):
    print("Yes It is a Pangram")
else:

    print("No It is not a Pangram")

Output::


Sunday, January 29, 2017

Filter Long Words

Question::

Write a function filter_long_words() that takes a list of words and an integer n and returns the list of words that are longer than n.

Code:

def filter_long_words(l,a):
    words=[]
    for j in l:
        if(len(j)>=a):
            words.append(j)
    return words

n=input("Enter words:")
nt=n.split(",")
na=input("Enter Min Length:")
long=filter_long_words(nt,int(na))

print("Words with at least min length:",long)

Output::

Longest Word in a List

Question::

Write a function find_longest_word() that takes a list of words and returns the length of the longest one

Code::
def longest(l):
    long=0
    word=""
    for j in l:
        if(long<len(j)):
            long=len(j)
            word=j
    return [word,long]

n=input("Enter words:")
nt=n.split(",")
long=longest(nt)

print("Longest Word with length:",long)

Output::

Mapping Python

Question::
Write a program that maps a list of words into a list of integers representing the lengths of the corresponding words.

Code::

def mapping(l):
    mapped=[]
    for j in l:
        mapped.append(len(j))
    return mapped

n=input("Enter words:")
nt=n.split(",")
mapped=mapping(nt)

print("Another List:",mapped)

Output::

Employee's Management in an Organization

Following program will help in managing employee's in an organization it ask details for each new employee and have functions for printing details of any employee and increment their salary by 5%.

Code::

import java.util.*;
class employee
{  Scanner in=new Scanner(System.in); 
    private String name;
    private double salary;
    private int year,month,day;
    employee()
    {
        System.out.print("Enter Name of Employee: ");
        name=in.nextLine();
        System.out.print("Enter Salary of Employee: ");
        salary=in.nextDouble();
        System.out.println("Enter Date of Joining(in DD/MM/YYYY format): ");
        System.out.print("Date:");
        day=in.nextInt();
        System.out.print("Month:");
        month=in.nextInt();
        System.out.print("Year: ");
        year=in.nextInt();
    }
    public void increment()
    {
        salary=salary+salary*0.05;
    }
    public void show()
    {
        System.out.println("Details of Employee: ");
        System.out.println("Name: "+name);
        System.out.println("Salary: "+salary);
        System.out.printf("Date of Joining: %d/%d/%d\n",day,month,year);
    }
}
public class Organization 
{
    public static void main(String[] nt) 
    {
        employee[] staff=new employee[2];
        staff[0]=new employee();
        staff[0].increment();
        staff[0].show();
    }
}

Output::


here you can declare any number of employees,i have declared only one and increment and show the details of that particular employee....