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]
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
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]
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?
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. -
import calendar
-
year = 2006
-
month = 10
-
day = 31
-
calendar.setfirstweekday(calendar.SUNDAY)
-
fd, nDays = calendar.monthrange(year, month)
-
if day > nDays:
-
print "not a valid date"
-
Please use [code] tags when you post back. Thanks,
Barton
- Input: the user inputs the amount in one of the following forms:
-
# C value
-
# F value
-
# CM value
-
# I value
-
#
-
# C - is a celcius value. Program converts to fahrenheit
-
# F - is a fahrenheit value. Program converts to celcius
-
# CM - is a centimetre value. Program converts to inches
-
# I - is an inch value. Program converts to centimetres
-
-
import sys
-
-
# Prompt user
-
sys.stdout.write( "Enter a value to convert: ")
-
-
# Read in a line from the keyboard
-
lineElements = sys.stdin.readline().split(" ")
-
-
# If the value is Celcius, convert to Fahrenheit
-
if lineElements[0].lower() == 'c':
-
print "%s degress celcius is %.2f degrees fahrenheit." \
-
% ( lineElements[1].strip(), (float(lineElements[1])*9.0/5.0)+32)
-
-
# If the value is Fahrenheit, convert to Celcius
-
elif lineElements[0].lower() == 'f':
-
print "%s degress fahrenheit is %.2f degrees celcius." \
-
% ( lineElements[1].strip(), (float(lineElements[1]) - 32) * 5.0/9.0)
-
-
# if the value is in centimetres, convert to inches
-
elif lineElements[0].lower() == 'cm':
-
print "%s centimetres is %.2f inches." % ( lineElements[1].strip(),
-
(float(lineElements[1]) * 0.3937))
-
-
# if the value is in inches, convert to centimetres
-
elif lineElements[0].lower() == 'i':
-
print "%s inches is %.2f centimetres." % ( lineElements[1].strip(),
-
(float(lineElements[1]) * 2.54))
Sorry wrong code...this is the right code - import sys
-
-
# 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.write("Please enter the day of the month (1-31): ")
-
dayOfMonth = int(sys.stdin.readline().strip())
-
-
sys.stdout.write("Please enter the month (1-12): ")
-
month = int(sys.stdin.readline().strip())
-
-
sys.stdout.write("Please enter the year: ")
-
year = int(sys.stdin.readline().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]
bartonc 6,596
Recognized Expert Expert
Sorry wrong code...this is the right code - import sys
-
-
# 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.write("Please enter the day of the month (1-31): ")
-
dayOfMonth = int(sys.stdin.readline().strip())
-
-
sys.stdout.write("Please enter the month (1-12): ")
-
month = int(sys.stdin.readline().strip())
-
-
sys.stdout.write("Please enter the year: ")
-
year = int(sys.stdin.readline().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]
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?
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... - def isLeap(year):
-
if year % 400 == 0:
-
return True
-
elif year % 4 == 0 and year % 100 !=0:
-
return True
-
else:
-
return False
-
-
def computeMaxDay(month, year):
-
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}
-
if month == 2:
-
if isLeap(year):
-
return 29
-
return maxDays[month]
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... - def isLeap(year):
-
if year % 400 == 0:
-
return True
-
elif year % 4 == 0 and year % 100 !=0:
-
return True
-
else:
-
return False
-
-
def computeMaxDay(month, year):
-
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}
-
if month == 2:
-
if isLeap(year):
-
return 29
-
return maxDays[month]
since
>>> 1996 %4
0
>>> 1997 %4
1
>>> 2000 %4
0
>>> not(2008 % 4)
True
>>>
You can simply -
def IsLeapYear(year):
-
return not (year % 4)
-
Sign in to post your reply or Sign up for a free account.
Similar topics |
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.
|
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...
|
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
|
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.
|
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.
| |
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>
|
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...
|
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...
|
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...
|
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...
|
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();...
| |
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...
|
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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...
| |