Python Modules and Packages, Date and Time Functions, File Handling
SUM OF THE INTEGERS IN THE FILE_PY
Rule:
The file name should be sample.txt.
Input format:
Give the input as a file which contains the integer values.
Output format:
The output will be the integer which is the sum of the integers. Display the output in the console.
Sample Input file (sample.txt):
1
2
3
4
5
Sample Output:
The sum of the integers in the file sample.txt is:15
NUMBER OF LINES IN THE FILE
Input format:
Input is a file. Filename: input.txt
Output format:
The output will be the integer which is the number of lines in the file. Display the output in the console.
Sample Input file (input.txt):
C was invented to write an operating system called UNIX.
C is a successor of B language which was introduced around 1970
The language was formalized in 1988 by the American National Standard Institue (ANSI).
By 1973 UNIX OS almost totally written in C.
Today C is the most widely used System Programming Language.
Most of the state of the art software have been implemented using C.
Easy to learn
Structured language
It produces efficient programs.
It can handle low-level activities.
It can be compiled on a variety of computers.
Sample Output 1:
The file has 11 lines
UPPERCASE IN FILES
Write a program to capitalize the first letter of every word in a file.
Input Format :
Input is a file. Filename: input.txt
Sample Input file (input.txt):
C was invented to write an operating system called UNIX.
C is a successor of B language which was introduced around 1970
The language was formalized in 1988 by the American National Standard Institue (ANSI).
By 1973 UNIX OS almost totally written in C.
Today C is the most widely used System Programming Language.
Most of the state of the art software have been implemented using C.
Easy to learn
Structured language
It produces efficient programs.
It can handle low-level activities.
It can be compiled on a variety of computers.
Sample Output file (output.txt)
C Was Invented To Write An Operating System Called UNIX.
C Is A Successor Of B Language Which Was Introduced Around 1970
The Language Was Formalized In 1988 By The American National Standard Institue (ANSI).
By 1973 UNIX OS Almost Totally Written In C.
Today C Is The Most Widely Used System Programming Language.
Most Of The State Of The Art Software Have Been Implemented Using C.
Easy To Learn
Structured Language
It Produces Efficient Programs.
It Can Handle Low-level Activities.
It Can Be Compiled On A Variety Of Computers.
REVERSE THE FILE
Rule:
The input file name should be input.txt and the output file name should be output.txt.
Sample Input File(input.txt):
A computer is a machine which helps us to calculate, simulate and store different scenarios. For example, in order to write an e-mail, instead of paper and pen first we use a software (or program) called wordprocessor which helps us enter sentences through keyboard (Input), computer's screen (output) to read, and modem (output/input) to send it to a distant relative, friend, etc.
Sample Output File(output.txt):
.cte ,dneirf ,evitaler tnatsid a ot ti dnes ot )tupni/tuptuo( medom dna ,daer ot )tuptuo( neercs s'retupmoc ,)tupnI( draobyek hguorht secnetnes retne su spleh hcihw rossecorpdrow dellac )margorp ro( erawtfos a esu ew tsrif nep dna repap fo daetsni ,liam-e na etirw ot redro ni ,elpmaxe roF .soiranecs tnereffid erots dna etalumis ,etaluclac ot su spleh hcihw enihcam a si retupmoc A
SEARCH BLOOD GROUP
Format of the file.txt file
Rajkumar,O+ve,Chennai
Chandrabose,B+ve,Chennai
Tamil Selvan,O+ve,Chennai
Ramkumar,B+ve,Chennai
Selvan,O+ve,Chennai
Input Format:
First line of the input consist of blood group.
Output Format:
Display the Donor Details.
[All text in bold corresponds to input and the rest corresponds to output]
Sample Input/Output 1 :
Sample Input/Output 2 :
Enter blood group to search
O-ve
Donor details
No donor found for the blood group O-ve
LEAP_YEAR_DATE_TIME
Input and output format:
Input consists of String.Date format should be(dd/mm/yyyy),Output contains the given date format is leap year or not.
[All Texts in bold corresponds to the input and rest are output]
Sample Input /Output 1:
Enter the date in format(dd/mm/yyyy)
19/05/1990
The year isn't a leap year!
Sample Input /Output 2:
Enter the date in format(dd/mm/yyyy)
12/05/2000
The year is a leap year!
Additional Sample TestCases
Sample Input and Output 1 :Enter the date in format(dd/mm/yyyy) 12/05/2000 The year is a leap year!Sample Input and Output 2 :
Enter the date in format(dd/mm/yyyy) 19/05/1990 The year isn't a leap year!
DATE_AGE
Input and output format:
Input consists of String.Date format should be(mm/dd/yyyy ).
1st line of the input indicates the date of birth and 2nd line of the input indicates the future date.
Output contains an integer indicates the current age of the person.
[All Texts in bold corresponds to the input and rest are output]
Sample Input /Output 1:
Enter Birth date as mm/dd/yyyy format:
05/11/1996
Enter Current date as mm/dd/yyyy format:
02/09/2018
The current age of the person is 21
Sample Input /Output 2:
Enter Birth date as mm/dd/yyyy format:
08/05/1953
Enter Current date as mm/dd/yyyy format:
01/04/2018
The current age of the person is 64
Additional Sample TestCases
Sample Input and Output 1 :Enter Birth date as mm/dd/yyyy format: 05/11/1996 Enter Current date as mm/dd/yyyy format: 02/09/2018 The current age of the person is 21Sample Input and Output 2 :
Enter Birth date as mm/dd/yyyy format: 08/05/1953 Enter Current date as mm/dd/yyyy format: 01/12/2018 The current age of the person is 64
DAYS_OF_THE_WEEK(DATE_TIME)
In a school,teacher asking the question regarding number of weeks most of the students answered correctly ,then teacher asked question like if you add 'n' number of days to given date what will be the name of the day,most of the student unable to answerd can you help them out to find the name of the day.
Input and output format:
Input consists of String.Date format should be(mm/dd/yyyy ).
1st line of the input indicates the date shoulb be(mm/dd/yyyy) format and 2nd line of the input represents integer.
Output contains name of the day after adding 'n' number of days.
Note:Use timedelta().
[All Texts in bold corresponds to the input and rest are output]
Sample Input /Output 1:
Enter the date as mm/dd/yyyy format:
03/09/2018
6
The day is : Thursday
Sample Input /Output 2:
Enter the date as mm/dd/yyyy format:
03/18/2018
2
Thedayis : Tuesday
Additional Sample TestCases
Sample Input and Output 1 :Enter the date as mm/dd/yyyy format: 03/09/2018 6 The day is : ThursdaySample Input and Output 2 :
Enter the date as mm/dd/yyyy format: 03/18/2018 2 The day is : Tuesday
DECODING_MONTH_NAME(DATE_TIME)
Decoding Month Names
Ram has created an application page for registration to Java Course and in that form ,there one field- date of birth. If any person fill the date of birth in(DD-MMM-YYYY) format it should be converted into (DD-MM-YYYY). So help Ram to update registration page that convert the date of birth ( DD-MMM-YYYY) format into (DD-MM-YYYY) format.
Input and output format:
Input consists of string.Date format should be(DD-MMM-YYYY).
Output contains string.Date should be in the decoded format.
[All Texts in bold corresponds to the input and rest are output]
Hint:
[Create a dictionary suitable for decoding month names to numbers.
Months in a dictionary should be in the following format: JAN for january , FEB for february, MAR for march and so on.. as keys and the corresponding numbers as values.]
Sample Input /Output 1:
Enter the date in format(DD-MMM-YYYY)
12-DEC-1997
12-12-1997
Sample Input /Output 2:
Enter the date in format(DD-MMM-YYYY)
03-MAR-1975
03-03-1975
Additional Sample TestCases
Sample Input and Output 1 :Enter the date in format(DD-MMM-YYYY) 12-DEC-1997 12-12-1997Sample Input and Output 2 :
Enter the date in format(DD-MMM-YYYY) 03-MAR-1975 03-03-1975
STOP_WATCH(DATE_TIME)
Stop Watch
Sita and Seema are best friends. One day they had a huge discussion about the time calculation. They were confused to find the diffrence between starting time and end time in milliseconds. So they both are planned to write a program to Difference between two time stamps in milliseconds.
Input and output format:
Input consists of String.Time format should be(HH:MM:SS ).Hours format should be '24 hours'.
1st line of the input indicates the start time and 2nd line of the input indicates the end time.
Output contains an integer indicates the difference between two times in milli seconds.
[All Texts in bold corresponds to the input and rest are output]
Sample Input /Output 1:
Start time
11:00:00
End time
12:10:00
Time in milliseconds is 4200000
Sample Input /Output 2:
Start time
10:00:00
End time
12:10:00
Time in milliseconds is 7800000
Additional Sample TestCases
Sample Input and Output 1 :Start time 11:00:00 End time 12:10:00 Time in milliseconds is 4200000Sample Input and Output 2 :
Start time 10:00:00 End time 12:10:00 Time in milliseconds is 7800000
NON-REAPEATING CHARACTER
Megha and Akila are playing string games. And Megha gives a string to Akila, and she has to find a first non-repeating character from that string. So help Akila by writing a program to find the first non-repeating character from that string.
Problem Constraints:
Create a Module named StringOpr.py contains a function named nonRepeat( str ):- which returns first non repeating character and sorted string.
Input Format:
The input consists of a string.
Output Format:
The output consists of a character that represents the non-repeating characters and string in sorted order.
If there is no non-repeating character in the string, then print '#'.
Note: All text in bold corresponds to input and the rest corresponds to output.
Sample Input 1:
swiiss
Sample Output 1:
w
iisssw
Sample Input 2:
naddan
Sample Output 2:
#
aaddnn
MODULE: STRING LAPINDROME
Ram and Ravi are good at string concepts. And Ram wants to check the capability of Ravi, whether she is good at string concepts or not. So he gave one string program to him. He has to find the string is Lapindrome or not. He explains the concept of Lapindrome is like:
Lapindrome is a string which divides the string into two halves, and check the letter frequency of both the strings same or not. If the string contains an odd number of characters, then we have to ignore the middle character.
So help him by writing a program to find the given string is Lapindrome or not.
Functional Requirements:
- Use def myFun () to read the multiple inputs to a function.
- Use import statements as per program requirements.
Input Format:
The input consists of a string.
Output Format:
The output is a string consists of "Lapindrome" or "Not a Lapindrome".
Note: All text in bold corresponds to input and the rest corresponds to output.
Sample Input 1:
sahas
Sample Output 1:
Lapindrome
Sample Input 2:
abcabd
Sample Output 2:
Not a Lapindrome
PACKAGE FOR NEAREST PRIME/PALINDROME
we might wish for a means of grouping and organizing them. So, Packages allow for a hierarchical structuring of the module namespace using dot notation. In the same way that modules help avoid collisions between global variable names, packages help avoid collisions between module names.

Write a program to create a package that contains modules to perform the following operations
if the number itself is prime no need to find, return that number itself, or else search for nearest, it can be to the left as well as to the right, if the distance between both numbers is the same then return left prime number.
Check whether the given number is palindrome or not
Problem Constraints:
Include __init__.py file in a package.
Note: Nearest prime can be either left or right of the number, absolute distance between them should be minimum. if number itself prime return as it is.
Input Format:
Output Format:
based on the conditions.
Note : If the user enters a choice other than 1 or 2 , then exit the program.
Note: All the bold lines in sample I/O format indicate input and rest correspond to output.
Sample I/O format 1:
Sample I/O format 2:
Additional Sample TestCases
Sample Input and Output 1 :Enter the choice 1.Nearest Prime number 2. Checking Palindrome number 3.Exit 1 Enter the number 144 Nearest Prime nuumber is 139 Do you want to continue?? (y/n) y Enter the choice 1.Nearest Prime number 2. Checking Palindrome number 3.Exit 2 Enter the number 121 121 is Palindrome number Do you want to continue?? (y/n) nSample Input and Output 2 :
Enter the choice 1.Nearest Prime number 2. Checking Palindrome number 3.Exit 2 Enter the number 12345 12345 is not Palindrome number Do you want to continue?? (y/n) y Enter the choice 1.Nearest Prime number 2. Checking Palindrome number 3.Exit 1 Enter the number 145 Nearest Prime number is 149 Do you want to continue?? (y/n) nSample Input and Output 3 :
Enter the choice 1.Nearest Prime number 2. Checking Palindrome number 3.Exit 1 Enter the number 354 Nearest Prime number is 353 Do you want to continue?? (y/n) y Enter the choice 1.Nearest Prime number 2. Checking Palindrome number 3.Exit 2 Enter the number 787 787 is Palindrome number Do you want to continue?? (y/n) y Enter the choice 1.Nearest Prime number 2. Checking Palindrome number 3.Exit 1 Enter the number 1000 Nearest Prime number is 997 Do you want to continue?? (y/n) y Enter the choice 1.Nearest Prime number 2. Checking Palindrome number 3.Exit 3
Problem Requirements:
Python2.7
| Keyword | Min Count | Max Count |
| def | 1 | - |
| Keyword | Min Count | Max Count |
| import | 1 | - |
USING PACKAGE_MODULE
BASIC MATHEMATICAL OPERATIONS USING PACKAGE
Requirement functionalities:
- it must include __init__.py file in the package
- Create a new package named "package" and the three modules.
- Modules names as addition,oddsum,jubliee
- import all the modules of package into the main program.
- First integer input will be choice of the given options
- if choice is 1, then it must intake 3 integer values as input(i.e x,n,m > 0)
- if the choice is 2, then it takes the input of single integer
- if the choice is 3, then it takes the input of single integer
- for choice 1, output will be result of modulo addition(n,x,m): r=(n+x)%m
- for choice 2, the output contains two integers first sum of even numbers and sum of odd numbers.
- for choice 3, the output contains a string stating whether a given number is Jubliee or not. (i.e numbers should start and end with 25)
Sample input 1 and sample output 1:
1.addition Modulo
2.Sum of odd and even
3:jubliee or not
1
55
7
8
6
Do you want to continue?(y/n)
y
1.addition Modulo
2.Sum of odd and even
3:jubliee or not
2
2314
6 4
Do you want to continue?(y/n)
y
1.addition Modulo
2.Sum of odd and even
3:jubliee or not
3
2567877625
jubliee
Do you want to continue?(y/n)
n
sample input 2 and Sample output 2:
1.addition Modulo
2.Sum of odd and even
3:jubliee or not
3
23242223
Do you want to continue?(y/n)
y
1.addition Modulo
2.Sum of odd and even
3:jubliee or not
2
4444
16 0
Do you want to continue?(y/n)
n
Additional Sample TestCases
Sample Input and Output 1 :1.addition Modulo 2.Sum of odd and even 3:jubliee or not 1 55 7 8 6 Do you want to continue?(y/n) y 1.addition Modulo 2.Sum of odd and even 3:jubliee or not 2 2314 6 4 Do you want to continue?(y/n) y 1.addition Modulo 2.Sum of odd and even 3:jubliee or not 3 2567877625 jubliee Do you want to continue?(y/n) nSample Input and Output 2 :
1.addition Modulo 2.Sum of odd and even 3:jubliee or not 2 4343 8 6 Do you want to continue?(y/n) y 1.addition Modulo 2.Sum of odd and even 3:jubliee or not 3 25687625 jubliee Do you want to continue?(y/n) y 1.addition Modulo 2.Sum of odd and even 3:jubliee or not 1 109 5 10 4 Do you want to continue?(y/n) nSample Input and Output 3 :
1.addition Modulo 2.Sum of odd and even 3:jubliee or not 3 23242223 not jubliee Do you want to continue?(y/n) y 1.addition Modulo 2.Sum of odd and even 3:jubliee or not 2 4444 16 0 Do you want to continue?(y/n) n
where the answer of this problem
ReplyDeletegive me answer ..it will be much helpful for me
DeleteYES,answers
Deletewhere the answer we can found
ReplyDelete