Monday, January 30, 2017

"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....

Lottery Draw Java

Following program will produce a ticket number with given no of digits randomly and will help in Lottery Draw :

Code::

import java.util.*;
public class LotteryDraw 
{
    public static void main(String[] nt) 
    {
        Scanner in=new Scanner(System.in);
        System.out.print("How many digits a ticket have: ");
        int k=in.nextInt();
        int [] num=new int[10];
        for(int i=0;i<num.length;i++)
        {
            num[i]=i;
        }
        int [] result=new int[k];
        for(int i=0;i<result.length;i++)
        {
            int r=(int)(Math.random()*10); //here 10 bcz the random function will produce positive value less than 1.0 
            result[i]=num[r];
        }
        System.out.print("So the Jackpot Ticket is: ");
        for(int i=0;i<result.length;i++)
        {
            System.out.print(result[i]);
        }
        System.out.println();
    }
}

Output::