Difference between revisions of "Rattlesnake 1"

From Grundy
Jump to navigation Jump to search
m
(Unhide Solution)
 
Line 3: Line 3:
 
'''Youtube Problem Statement''': [https://www.youtube.com/watch?v=owsqKkR2Bc0&t=10s https://www.youtube.com/watch?v=owsqKkR2Bc0&t=10s]
 
'''Youtube Problem Statement''': [https://www.youtube.com/watch?v=owsqKkR2Bc0&t=10s https://www.youtube.com/watch?v=owsqKkR2Bc0&t=10s]
  
<!-- '''Youtube Solution''': [https://www.youtube.com/watch?v=Wzqknem7umY https://www.youtube.com/watch?v=Wzqknem7umY]  
+
'''Youtube Solution''': [https://www.youtube.com/watch?v=Wzqknem7umY https://www.youtube.com/watch?v=Wzqknem7umY]  
  
'''Solution Upload Link''': [https://codeboard.io/projects/39211 https://codeboard.io/projects/39211] -->
+
<!-- '''Solution Upload Link''': [https://codeboard.io/projects/39211 https://codeboard.io/projects/39211] -->
  
 
== Problem Statement: ==
 
== Problem Statement: ==
Line 26: Line 26:
 
- Y
 
- Y
  
<!-- == Solution: ==
+
== Solution: ==
  
 
<syntaxhighlight lang="python" line>
 
<syntaxhighlight lang="python" line>
Line 44: Line 44:
  
 
</syntaxhighlight>
 
</syntaxhighlight>
-->
+
 
  
 
== See also ==
 
== See also ==
Line 51: Line 51:
 
* [http://wncc-iitb.org/wiki/index.php/Functional_Aspects_of_Python Functional Aspect of Python]
 
* [http://wncc-iitb.org/wiki/index.php/Functional_Aspects_of_Python Functional Aspect of Python]
 
* [http://wncc-iitb.org/wiki/index.php/Rattlesnake Rattlesnake]
 
* [http://wncc-iitb.org/wiki/index.php/Rattlesnake Rattlesnake]
 +
* [http://wncc-iitb.org/wiki/index.php/Rattlesnake_2 Rattlesnake #2]

Latest revision as of 00:57, 9 October 2017

Date: 1st October 2017

Youtube Problem Statement: https://www.youtube.com/watch?v=owsqKkR2Bc0&t=10s

Youtube Solution: https://www.youtube.com/watch?v=Wzqknem7umY


Problem Statement:

Write a program in python to convert a given date to a day. The program should run in a loop and should keep asking if the user wants to quit. If the user wants to continue, he should be prompted to enter the date he wants to convert again.

Input format: You can choose any input format you want. However preferably it should be DD/MM/YYYY.

Output Format: The output should be the weekday, like "Monday", "Saturday" etc.

Example:

Enter a date to convert (DD/MM/YYYY):

- 14/01/2017

Saturday

Do you want to quit? (Y/N)

- Y

Solution:

 1     import datetime
 2     def convert(day, month, year):
 3         date = datetime.datetime.strptime(month + " " + day + ", " + year, "%m %d, %Y")
 4         return date.strftime('%A')
 5     while True:
 6         print "Enter a date in the DD/MM/YYYY format"
 7         date = raw_input()
 8         date_arr = date.split("/")
 9         day = convert(date_arr[0], date_arr[1], date_arr[2])
10         print "The day of the week is " + day
11         option = raw_input("Do you wish to quit? (Y/N)")
12         if option == "Y":
13         	break


See also