CS 135 Exam 3

docx

School

University of North Alabama *

*We aren’t endorsed by this school

Course

CS-135

Subject

Computer Science

Date

Jan 9, 2024

Type

docx

Pages

3

Uploaded by MateEnergy12978

Report
Problem Specification: Write a program to take as input a year and return to the user whether or not the year is a leap year. Input: year_input, converted to an integer using the int() function. This ensures that whatever the user inputs via input() —which typically receives data as a string—is converted into an integer data type. The ‘year’ list is technically an input but isn’t utilized in the code and includes the test cases. Output: the output is in the form of a string that includes the input year and the determination of whether it's a leap year or not. String interpolation is used to create the output message 2000 Leap year 2023 Not leap year 2024 Leap year 2100 Not leap year Pseudocode: FUNCTION is_leap_year(year): IF year modulo 4 equals 0 AND (year modulo 100 not equals 0 OR year modulo 400 equals 0): RETURN True ELSE: RETURN False Flow chart:
(I wasn’t sure how you wanted this in the Word doc so I just took a screenshot) Python code: #CS 135 Laine Stinnett leap year def is_leap_year(year): if year % 4 == 0 and (year % 100 != 0 or year % 400 == 0): return True else: return False # Taking input from the user
year_input = int(input("Enter a year: ")) # Checking if the input year is a leap year or not if is_leap_year(year_input): print(f"{year_input} is a leap year.") else: print(f"{year_input} is not a leap year.") Screenshot of Code in Execution:
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help