Skip to content

Commit

Permalink
Merge pull request #451 from Ashu-1309/days_finder
Browse files Browse the repository at this point in the history
Days Finder In A Month
  • Loading branch information
prathimacode-hub committed Jun 25, 2021
2 parents ece79ba + b2d6e01 commit 36290e4
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 0 deletions.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
44 changes: 44 additions & 0 deletions BasicPythonScripts/Finding Number of Days in a Month/README.md
@@ -0,0 +1,44 @@
# Finding the Number of Days in a Month
## Aim :- Finding the Number of Days in a Month

## Purpose :-
-To find the number of days in a month.

## WorkFlow :_

## Script used in Finding the Number of Days in a Month
-First we will import datetime libray
-Then def main function in which user have to give input as year and month.
-The strptime() method creates a datetime object from the given string.
-THen it will call the days_finder() function and perform certain operation and give output.

### main() :- It will take input from user as year and month and call other function.

### days_finder :-It will perform operation and give the desired output .

### choice :- It choice selection function used to make decision.

## Compilation steps:-

-import datetime libray to finding the name of month

-days_finder() is function that will be called for finding the number of days in mmonth.

-After performing the operation , I gave the option whether user want to continue or exit.

-If want to co continue enter 1 or else to Exit.


## Setup instructions
-User needs any python id and compiler to execute the program.


## Display images/gifs/videos of output/result of your script so that users can visualize it
https://github.com/Ashu-1309/Awesome_Python_Scripts/blob/829ca05abf0f10c77fdd060db4ced2d544f30dd1/BasicPythonScripts/Finding%20Number%20of%20Days%20in%20a%20Month/Images/Day%20Finder.png



## Author(s)
ASHUTOSH KUMAR SAW <br>
LGMSOC <br>
CONTRIBUTOR
@@ -0,0 +1,41 @@
# This code will be used to find out the Numbers of day in a month.
print(" -- This code is used to find the Number of days in a Month-- ")
days_finder.py
import datetime


def days_finder(month_number, year): #defining the functon to find the number of days in a month
leap = 0 #assigning value
print(month_number)
list_31 = [1, 3, 5, 7, 8, 10, 12] # Listing Out month number having 31 days
list_30 = [4, 6, 9, 11] # Listing Out month number having 31 days
if year % 4 == 0: # Condition checking for leap year
leap = 1
if month_number in list_30: # Condition check for 30 days
number_of_days = 30
elif month_number in list_31: # Condition checking for 31 days
number_of_days = 31
else: #Condition checking for 28 days
number_of_days = 28 + leap # if month is feb and its leap year than leap + 1 so it will become 29 days
return number_of_days


def main(): # main function
year = int(input("Enter the year ")) # user input (year )
month_number = (input(' Enter the Name of Month ')) #user input (month)
datetime_object = datetime.datetime.strptime(month_number, "%m") # calling datetime libray for month finding

month_name = datetime_object.strftime("%B") # This Section will give month name as output
month_number = int(month_number)

print("The Number of days in ",month_name ," is " ,days_finder(month_number, year))

choice=int(input("Enter 1 to Continue or else to exit "))
if choice == 1:
main()
else:
exit


main()

@@ -0,0 +1,8 @@
##requirement

import datetime


use strptime method to create a datetime object

%B is used to give Full Month Name.

0 comments on commit 36290e4

Please sign in to comment.