473,698 Members | 2,747 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

zellers congrunence

14 New Member
1. How do I keep prompting the user for more dates until the user has indicated that he/she wishes to quit.
2. Computation of the day of the week MUST be moved to its own function.
3. How do I verify that the date entered is valid. For example, April only has 30 days so the user will not be allowed to enter April 31 as a valid date. See input section below to see how this is to be accomplished.
4. I have 2 functions which will help me ensure that the user enters a valid date. How do I integrate these functions into your solution.

# dictionary of day names for output.
dayNames = {0:"Saturday", 1:"Sunday", 2:"Monday", 3:"Tuesday", 4:"Wednesday" ,
5:"Thursday", 6:"Friday"}

# Get user input: month, day, year
sys.stdout.writ e("Please enter the day of the month (1-31): ")
dayOfMonth = int(sys.stdin.r eadline().strip ())

sys.stdout.writ e("Please enter the month (1-12): ")
month = int(sys.stdin.r eadline().strip ())

sys.stdout.writ e("Please enter the year: ")
year = int(sys.stdin.r eadline().strip ())

# Make adjustments for forumla
if month == 1 or month == 2:
month = month + 12
year = year - 1

# Compute coefficients
century = year/100
yearInCentury = year % 100

# Compute the day using Zeller's congruence
dayOfWeek = (dayOfMonth + ((month + 1)* 26)/10 + yearInCentury +
(yearInCentury/4) + (century/4) - 2*century) % 7

# Output answer
print "Day of week is %s" % dayNames[dayOfWeek]
Oct 31 '06 #1
12 7537
bartonc
6,596 Recognized Expert Expert
Please post back using [ code ] [ /code ] (but without spaces) tags around your code. Otherwise, we can't see the structure of you code. Thanks.

for example
Expand|Select|Wrap|Line Numbers
  1.  
  2. # this is code
  3.  
Oct 31 '06 #2
bratiskovci
14 New Member
here is the code...
# dictionary of day names for output.
dayNames = {0:"Saturday", 1:"Sunday", 2:"Monday", 3:"Tuesday", 4:"Wednesday" ,
5:"Thursday", 6:"Friday"}

# Get user input: month, day, year
sys.stdout.writ e("Please enter the day of the month (1-31): ")
dayOfMonth = int(sys.stdin.r eadline().strip ())

sys.stdout.writ e("Please enter the month (1-12): ")
month = int(sys.stdin.r eadline().strip ())

sys.stdout.writ e("Please enter the year: ")
year = int(sys.stdin.r eadline().strip ())

# Make adjustments for forumla
if month == 1 or month == 2:
month = month + 12
year = year - 1

# Compute coefficients
century = year/100
yearInCentury = year % 100

# Compute the day using Zeller's congruence
dayOfWeek = (dayOfMonth + ((month + 1)* 26)/10 + yearInCentury +
(yearInCentury/4) + (century/4) - 2*century) % 7

# Output answer
print "Day of week is %s" % dayNames[dayOfWeek]
Nov 1 '06 #3
bartonc
6,596 Recognized Expert Expert
I'll work on the date thing. I want you to do the loop based on your other post, OK?
Nov 1 '06 #4
bartonc
6,596 Recognized Expert Expert
Here's some date stuff for you to play with. Also look at the datetime module in the standard library.
Expand|Select|Wrap|Line Numbers
  1. import calendar
  2. year = 2006
  3. month = 10
  4. day = 31
  5. calendar.setfirstweekday(calendar.SUNDAY)
  6. fd, nDays = calendar.monthrange(year, month)
  7. if day > nDays:
  8.     print "not a valid date"
  9.  
Please use [code] tags when you post back. Thanks,
Barton
Nov 2 '06 #5
bratiskovci
14 New Member
Expand|Select|Wrap|Line Numbers
  1.  Input: the user inputs the amount in one of the following forms:
  2. #         C value
  3. #         F value
  4. #         CM value
  5. #         I value
  6. #
  7. # C - is a celcius value.  Program converts to fahrenheit
  8. # F - is a fahrenheit value.  Program converts to celcius
  9. # CM - is a centimetre value.  Program converts to inches
  10. # I - is an inch value.  Program converts to centimetres
  11.  
  12. import sys
  13.  
  14. # Prompt user
  15. sys.stdout.write( "Enter a value to convert: ")
  16.  
  17. # Read in a line from the keyboard
  18. lineElements = sys.stdin.readline().split(" ")
  19.  
  20. # If the value is Celcius, convert to Fahrenheit
  21. if lineElements[0].lower() == 'c':
  22.     print "%s degress celcius is %.2f degrees fahrenheit." \
  23.           % ( lineElements[1].strip(), (float(lineElements[1])*9.0/5.0)+32)
  24.  
  25. # If the value is Fahrenheit, convert to Celcius
  26. elif lineElements[0].lower() == 'f':
  27.     print "%s degress fahrenheit is %.2f degrees celcius." \
  28.           % ( lineElements[1].strip(), (float(lineElements[1]) - 32) * 5.0/9.0)
  29.  
  30. # if the value is in centimetres, convert to inches
  31. elif lineElements[0].lower() == 'cm':
  32.     print "%s centimetres is %.2f inches." % ( lineElements[1].strip(),
  33.                                              (float(lineElements[1]) * 0.3937))
  34.  
  35. # if the value is in inches, convert to centimetres
  36. elif lineElements[0].lower() == 'i':
  37.     print "%s inches is %.2f centimetres." % ( lineElements[1].strip(),
  38.                                              (float(lineElements[1]) * 2.54))
Nov 3 '06 #6
bratiskovci
14 New Member
Sorry wrong code...this is the right code

Expand|Select|Wrap|Line Numbers
  1. import sys
  2.  
  3. # dictionary of day names for output.
  4. dayNames = {0:"Saturday", 1:"Sunday", 2:"Monday", 3:"Tuesday", 4:"Wednesday",
  5.  5:"Thursday", 6:"Friday"}
  6.  
  7. # Get user input:  month, day, year
  8. sys.stdout.write("Please enter the day of the month (1-31): ")
  9. dayOfMonth = int(sys.stdin.readline().strip())
  10.  
  11. sys.stdout.write("Please enter the month (1-12): ")
  12. month = int(sys.stdin.readline().strip())
  13.  
  14. sys.stdout.write("Please enter the year: ")
  15. year = int(sys.stdin.readline().strip())
  16.  
  17. # Make adjustments for forumla 
  18. if month == 1 or month == 2:
  19.     month = month + 12
  20.     year = year - 1
  21.  
  22. # Compute coefficients
  23. century = year/100
  24. yearInCentury = year % 100
  25.  
  26. # Compute the day using Zeller's congruence
  27. dayOfWeek = (dayOfMonth + ((month + 1)* 26)/10 + yearInCentury +
  28.              (yearInCentury/4) + (century/4) - 2*century) % 7
  29.  
  30. # Output answer
  31. print "Day of week is %s" % dayNames[dayOfWeek]
Nov 3 '06 #7
bartonc
6,596 Recognized Expert Expert
Sorry wrong code...this is the right code

Expand|Select|Wrap|Line Numbers
  1. import sys
  2.  
  3. # dictionary of day names for output.
  4. dayNames = {0:"Saturday", 1:"Sunday", 2:"Monday", 3:"Tuesday", 4:"Wednesday",
  5. 5:"Thursday", 6:"Friday"}
  6.  
  7. # Get user input: month, day, year
  8. sys.stdout.write("Please enter the day of the month (1-31): ")
  9. dayOfMonth = int(sys.stdin.readline().strip())
  10.  
  11. sys.stdout.write("Please enter the month (1-12): ")
  12. month = int(sys.stdin.readline().strip())
  13.  
  14. sys.stdout.write("Please enter the year: ")
  15. year = int(sys.stdin.readline().strip())
  16.  
  17. # Make adjustments for forumla 
  18. if month == 1 or month == 2:
  19. month = month + 12
  20. year = year - 1
  21.  
  22. # Compute coefficients
  23. century = year/100
  24. yearInCentury = year % 100
  25.  
  26. # Compute the day using Zeller's congruence
  27. dayOfWeek = (dayOfMonth + ((month + 1)* 26)/10 + yearInCentury +
  28. (yearInCentury/4) + (century/4) - 2*century) % 7
  29.  
  30. # Output answer
  31. print "Day of week is %s" % dayNames[dayOfWeek]
Awesome! You can post using tags! That's great.
Now you have some more things to work on after you copy the pieces from my last posts.
You CAN copy and paste to and from the forum, right?
Nov 3 '06 #8
bratiskovci
14 New Member
I am trying to incorporate this code into this program but I am have trouble getting to run properly. These functions are used for leap years...

Expand|Select|Wrap|Line Numbers
  1. def isLeap(year):
  2.     if year % 400 == 0:
  3.         return True
  4.     elif year % 4 == 0 and year % 100 !=0:
  5.         return True
  6.     else:
  7.         return False
  8.  
  9. def computeMaxDay(month, year):
  10.     maxDays = {1:31, 2:28, 3:31, 4:30, 5:31, 6:30, 7:31, 8:31, 9:30, 10:31, 11:30, 12:31}
  11.     if month == 2:
  12.         if isLeap(year):
  13.             return 29
  14.     return maxDays[month]
Nov 6 '06 #9
bartonc
6,596 Recognized Expert Expert
I am trying to incorporate this code into this program but I am have trouble getting to run properly. These functions are used for leap years...

Expand|Select|Wrap|Line Numbers
  1. def isLeap(year):
  2. if year % 400 == 0:
  3. return True
  4. elif year % 4 == 0 and year % 100 !=0:
  5. return True
  6. else:
  7. return False
  8.  
  9. def computeMaxDay(month, year):
  10. maxDays = {1:31, 2:28, 3:31, 4:30, 5:31, 6:30, 7:31, 8:31, 9:30, 10:31, 11:30, 12:31}
  11. if month == 2:
  12. if isLeap(year):
  13. return 29
  14. return maxDays[month]
since

>>> 1996 %4
0
>>> 1997 %4
1
>>> 2000 %4
0
>>> not(2008 % 4)
True
>>>
You can simply
Expand|Select|Wrap|Line Numbers
  1. def IsLeapYear(year):
  2.     return not (year % 4)
  3.  
Nov 6 '06 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

6
25363
by: aarklon | last post by:
Hi folks, I found an algorithm for calculating the day of the week here:- http://www.faqs.org/faqs/calendars/faq/part1/index.html in the section titled 2.5 what day of the week was 2 august 1953 I checked the algorithm it is very correct.
5
1597
by: bratiskovci | last post by:
Hello, I am trying to write a few programs using python but don't really know where to start...I am completely CONFUSED. My first program deals with conversion between fahrenheit and celcius and between centimetres and inches. example: Enter a value to convert: C100 100 degrees celcius is 212.0 degrees fahrenheit. My second problem deal with Zellers Congruence, which a program that tells us upon which day of the week a given date...
2
1348
by: bratiskovci | last post by:
I have to write a genetics program: This is the INPUT: 25 sets of genetic sequences are provided. Each sample is provided in a specific format so that my program may read in the genetic information for the purposes of processing. The following is the first genetic sequence provided: Sample 0:CTACGCTATC Sample 1:TTACGCTATC Sample 2:TTACGCTATC Sample 3:TTACGCTATC Sample 4:TTACGCTATC
9
4558
by: iHateProg | last post by:
I am looking for a day of birth generator that will use MONTH DATE AND YEAR born to generate the BIRTH DAY from 1900-2000. Ex:- If someone was born on April 10, 1990. what day of the week were they born on? Please help & Thank you for any help.
1
2824
by: ntraviglia | last post by:
Can anyone help? I have to write a zellers congruence program with visual. Anyone have any sample code or maybe the actual zeller program in visual they can give me, I am totally lost.
12
1822
by: Justn226 | last post by:
anyone have any idea why i am not getting any return values? it will return the words just not the numbers? HTML <HTML> <head> <title>Zellers Carpeting Cost Estimate</title> </head> <script>
0
9031
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8876
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7741
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6531
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5867
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4372
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3052
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2341
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2007
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.