1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
natita [175]
3 years ago
3

Writing a Modular Program in Python

Computers and Technology
1 answer:
Serga [27]3 years ago
6 0

Answer:

Add these statements to the given code:

if validDate == True:  #if the date is valid

   print(str(month)+'/'+str(day)+'/'+str(year) + " is a valid date")  #prints the statement in month/day/year format. str() converts the values of month day and year to string

else:  #if data is not valid

   print(str(month)+'/'+str(day)+'/'+str(year) + " is an invalid date") #prints this statement in month/day/year format

Explanation:

Here is the complete program:

validDate = True

MIN_YEAR = 0

MIN_MONTH = 1

MAX_MONTH = 12

MIN_DAY = 1

MAX_DAY = 31

year = int(input("Enter year:"))

month = int(input("Enter month:"))

day = int(input("Enter day:"))

if int(year) <= MIN_YEAR:  

    validDate = False

elif int(month) < MIN_MONTH or int(month) > MAX_MONTH:

    validDate = False

elif int(day) < MIN_DAY or int(day) > MAX_DAY:

    validDate = False

if validDate == True:

   print(str(month)+'/'+str(day)+'/'+str(year) + " is a valid date")  

else:

   print(str(month)+'/'+str(day)+'/'+str(year) + " is an invalid date")

I will explain the program with an example:

Suppose user enters 2002 as year, 9 as month and 21 as day so

year = 2002

month = 9

day = 21

All these are integers

validDate is set to True initially.

MIN_YEAR is set to 0 initially.

MIN_MONTH is set to 1  initially

MAX_MONTH is set to 12 initially

MIN_DAY is set to 1  initially

MAX_DAY is set to 31  initially

The first if condition if int(year) <= MIN_YEAR: checks if the year is less than MIN_YEAR. As the value of year is 2002 and that of MIN_YEAR is 0 so year is not less than or equals to MIN_YEAR. So this if condition evaluates to false. Thus the program moves to the elif part. The value of validDate remains true.

The elif condition elif int(month) < MIN_MONTH or int(month) > MAX_MONTH: checks if the month is less than MIN_MONTH  or greater than MAX_MONTH . Since the value of month is 9 so it is not less than value of MIN_MONTH which is 1 and it is not greater than the value of MAX_MONTH  which is 12. So this condition evaluates to false. Thus the program moves to the second elif part. The value of validDate remains true.

The elif condition elif int(day) < MIN_DAY or int(day) > MAX_DAY:  checks if the day is less than MIN_DAY  or greater than MAX_DAY. This is also not true because of value of day is 21 and it is not less than value of MIN_DAY which is 1 and it is not greater than value of MAX_DAY which is 31. So this condition also evaluates to false. So the program moves to the next statement. However the value of validDate remains true.

The next statement: if validDate == True:  evaluates to true because none of the above if elif conditions evaluate to true. Since this condition evaluate to true then statement in this if part executes which is:

   print(str(month)+'/'+str(day)+'/'+str(year) + " is a valid date")  

This is a print statement that prints the output on screen. str() method is used to convert the values of month, day and year to string form. So the output of this entire program is:

9/21/2002 is a valid date    

The program along with its output is attached in a screenshot.

You might be interested in
QUIZLET Packet ________ is a form of protection for your computer that looks at each packet that comes into your computer networ
anastassius [24]

Answer:Screening

Explanation:Packet screening is the process in which whenever a packet is received at the destination port, there is the examining of the packet.The examination of the packet rote from source to destination takes place. The screening takes place for evaluating that the data in the packet is adequate and carries no error that can risk in the security, tracks the routes  of the packet path etc.

5 0
3 years ago
The ability to present an effective message with useful content is obviously important to a good _____ presentation.
Zina [86]

A successful oral presentation depends on your ability to communicate your ideas clearly and with relevant content.

<h3>What is an oral expression? </h3>
  • Oral presentations, often known as public speaking or just presentations, involve one or more speakers discussing a particular topic with an audience.
  • This seeks to provide information, amuse, educate, and/or make a point.
  • When the author speaks in front of other students, coworkers, or other interested groups to convey the results of years of expertise and research while outlining essential elements to success, the book is referred to as an example of oral presentation.
  • An oral presentation is one of the best venues for fusing verbal prowess with powerful nonverbal indicators to extend your communication.
  • It enables people to speak in front of a live audience with assurance about their thoughts and opinions.

To learn more about Oral presentation, refer to:

brainly.com/question/27326303

#SPJ4

7 0
2 years ago
Ethernet is a standard communication protocol embedded in software and hardware devices used for building a local area network (
kupik [55]
<span>Ethernet is a standard communication protocol embedded in software and hardware devices used for building a local area network (LAN). 
a. True 
b. False</span>
5 0
3 years ago
How does Botnet operate and communicate.
zhuklara [117]

Answer:

 Botnet is typically operate by the internet relay networking and domain. The botnet are generally received specific type of the instruction from the control server.

The main purpose and structure of botnet is basically depend upon the various type of instruction and structure.

The botnet is communicated with the help of IRC ( Internet relay chat) and it is basically communicated with the chat server for transferring the data to the client. The IRC network basically use simple network with low bandwidth for communication with the host of the botnet.

4 0
3 years ago
A(n) _____ measures the ability to juggle a variety of demands, as in a manager's job where the candidate is presented with simu
Tju [1.3M]

Answer: in-basket test

Explanation:

An in-basket test or an in-basket exercise is a test used by firms or governments in recruiting and promoting employees. During the test, job applicants receive some mails, telephone calls, documents and memos.

3 0
4 years ago
Other questions:
  • Which company is credited with solving a problem by creating a program that could work on all computers?
    11·1 answer
  • A user is trying to delete a file located on an NTFS volume on his Windows 8 computer but is unable to do so. Why is this?
    6·1 answer
  • What is the output of the following function if the array nums contains the values 1 2 3 4 5 int backwards(int nums[]) { for (x
    15·1 answer
  • Instructions:Select the correct answer.
    6·2 answers
  • What is the definition of “potential energy”?
    6·1 answer
  • What function does a resource manager in an IDE perform?
    14·1 answer
  • what is required to successfully establish a connection between two routers using chap authentication?
    14·1 answer
  • which kind of system software tells the computer how to communicate with peripherals, such as a printer or scanner?
    7·1 answer
  • This feature allows you to adjust your view to see the lower and upper part of a document
    15·2 answers
  • The ____ line for any e-mail messages you write should clearly state the intention of the e-mail..
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!