0% found this document useful (0 votes)
20 views19 pages

Pcap - 1 Obje-Qe

The document contains a series of questions and answers related to Python's calendar and time modules. It covers various functions, parameters, and their expected outputs, focusing on the behavior of functions like calendar.monthrange, calendar.prcal, and time.time. The questions include multiple-choice formats, testing knowledge on how to manipulate and retrieve calendar-related information in Python.

Uploaded by

gautamchandan25
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views19 pages

Pcap - 1 Obje-Qe

The document contains a series of questions and answers related to Python's calendar and time modules. It covers various functions, parameters, and their expected outputs, focusing on the behavior of functions like calendar.monthrange, calendar.prcal, and time.time. The questions include multiple-choice formats, testing knowledge on how to manipulate and retrieve calendar-related information in Python.

Uploaded by

gautamchandan25
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 19

Pcap-object type questions

Topics- calendar modules in python

230008413_ Gautam Kumar:


Type of modules:
calendar.monthrange(year, month)/ calendar.prcal(year, w=2, l=1, c=6, m=3)

1. What does calendar.monthrange(2025, 7) return?

a) A tuple with two values

b) The number of days in July 2025

c) A string representation of July 2025

d) The weekday July 2025 starts on

Answer: a) A tuple with two values (single correct)

(It returns a tuple like (3, 31), where 3 is the starting weekday and 31 is the number of days.)

2. (Multiple Correct) Which of the following are true about the tuple returned by calendar.
monthrange(2024, 2)?

a) The first value is between 0 and 6

b) The second value is always 30 or 31

c) The first value represents the weekday the month starts on

d) The second value represents the number of days in the month

Answers: a) The first value is between 0 and 6, c) The first value represents the weekday the month starts
on, d) The second value represents the number of days in the month (b is false because February can
have 28 or 29 days.)

3. What does the c parameter in calendar.prcal(2025, w=2, l=1, c=8, m=3) control?
a) The number of columns in the output

b) The spacing between month columns

c) The width of date columns

d) The number of months per row

Answer: b) The spacing between month columns (single correct)

4. (Multiple Correct) Which values can the first element of the calendar?monthrange(2023, 12) tuple take?

a) 0 (Monday)

b) 6 (Sunday)

c) 7 (Beyond Sunday)

d) 4 (Thursday)

Answers: a) 0 (Monday), b) 6 (Sunday), d) 4 (Thursday)

(The first element is always 0 to 6, representing Monday to Sunday; 7 is invalid.)

5. What is the purpose of calendar.prcal(2025)?

a) Prints a calendar for 2025 to the console

b) Returns a list of all days in 2025

c) Sets the first weekday to Sunday

d) Calculates leap days in 2025

Answer: a) Prints a calendar for 2025 to the console (single correct)

6. (Multiple Correct) Which of the following can calendar.monthrange(2025, 4)[1] represent? a)

28

b) 29
c) 30

d) 31

Answer: c) 30

(April 2025 has 30 days, so only c is correct here; this is effectively single-correct due to the specific month.)

7. In calendar.prcal(2024, w=3, l=2, c=6, m=3), what does the l parameter affect?

a) The number of lines per week

b) The number of months per row

c) The width of the calendar

d) The spacing between columns

Answer: a) The number of lines per week (single correct)

8. (Multiple Correct) Which parameters in calendar.prcal(2025, w=2, l=1, c=6, m=3) directly affect the layout
of the printed calendar?

a) w (width of date columns)

b) l (lines per week)

c) c (spacing between columns)

d) m (months per row)

Answers: a) w, b) l, c) c, d) m

(All four parameters control the visual layout.)

9. What will calendar.monthrange(2024, 2) return if 2024 is a leap year? a)

(5, 28)

b) (5, 29)

c) (6, 28)
d) (6, 29)

Answer: b) (5, 29) (single correct)

(February 2024 starts on Thursday (5) and has 29 days as it’s a leap year.)

10. (Multiple Correct) Which of the following statements are true about calendar.prcal(2025)? a)

It prints a full-year calendar

b) It uses the default first weekday setting

c) It returns a string value

d) It can be customized with parameters like w, l, c, and m

Answers: a) It prints a full-year calendar, b) It uses the default first weekday setting, d) It can be customized
with parameters like w, l, c, and m

(c is false because it prints directly to the console, not returns a string.)


2300082085_chanikya pavan:
Type of modules:
calendar.timegm(tuple)/ calendar.setfirstweekday(weekday)
calendar.prmonth(year, month, w=0, l=0)
1.What does the function calendar.prmonth(year, month, w=0, l=0) do?

A) Prints the year calendar

B) Prints the month calendar

C) Returns the month calendar as a string

D) Converts the month calendar to HTML

2.What is the return type of calendar.prmonth(2024, 4)?

A) NoneType

B) str

C) int

D) tuple

3.Which of the following does calendar.setfirstweekday(weekday) affect?

A) The year calendar

B) The format of the date

C) The start of the week in the calendar display

D) The number of days in a month

4.What is the valid range for the weekday argument in calendar.setfirstweekday(weekday)?

A) 0 to 6

B) 1 to 7

C) 0 to 12

D) 1 to 6

5.What does calendar.timegm(tuple) return?

A) Unix timestamp
B) Month number

C) Weekday number

D) Current date and time

6.What is the output type of calendar.timegm((2024, 4, 1, 12, 0, 0, 0, 0, 0))?

A) datetime.date

B) str

C) int

D) float

7.How do you call calendar.prmonth() to print the calendar for May 2024?

A) calendar.prmonth(2024, 5)

B) calendar.prmonth(5, 2024)

C) calendar.prmonth(2024)

D) calendar.prmonth(5)

8.What happens if you call calendar.setfirstweekday(7)?

A) It sets the first weekday to Sunday

B) It throws an error because the valid range is 0 to 6

C) It starts the week on a random weekday

D) It sets Monday as the first weekday

9.What is the purpose of the w and l parameters in calendar.prmonth(year, month, w=0, l=0)?

A) To set the week width and line length for printing

B) To define the first day of the week

C) To specify the number of months to print

D) To select the calendar format

10.Can you set calendar.setfirstweekday(3) to start the week on Wednesday?

A) Yes, 3 represents Wednesday

B) No, the valid range is 0 to 6


C) Yes, but only in a non-Gregorian calendar

D) No, it will throw an error

11.What is the result of calling calendar.timegm() without arguments?

A) Returns the current Unix timestamp

B) Throws an error because a tuple is required

C) Returns None

D) Returns today's date in Unix timestamp format

12.How does calendar.prmonth() handle months with less than 7 days?

A) It prints a blank month

B) It adjusts the display automatically

C) It will not print the month

D) It throws an error

13.What does calendar.timegm() accept as input?

A) A time tuple in time.gmtime() format

B) A string containing a date

C) A timestamp

D) A datetime object

14.What happens when you call calendar.setfirstweekday(0)?

A) It sets Sunday as the first day of the week

B) It sets Monday as the first day of the week

C) It throws an error because 0 is not valid

D) It sets Saturday as the first day of the week

15. When would you use calendar.timegm()?

A) To convert a datetime.date object to a Unix timestamp

B) To set the first day of the week

C) To print the calendar for a month


D) To convert a time.gmtime() result to a Unix timestamp

16. How does calendar.setfirstweekday(6) affect the calendar output?

A) It starts the week on Saturday

B) It starts the week on Sunday

C) It sets Monday as the first day of the week

D) It causes the calendar to print incorrectly

17. Can calendar.prmonth() print a calendar for a month in the future, like May 2030?

A) Yes, it can print any month in the future

B) No, it only works for current or past months

C) Yes, but it will print errors for future months

D) No, it throws an error

18. What happens if you pass calendar.prmonth(2024, 2, w=10)?

A) The calendar will not print correctly because w cannot be greater than 6

B) It prints the month, but w will have no effect

C) It will print the month calendar with increased width

D) It will throw an error

19. What does calendar.setfirstweekday(1) do?

A) It sets Sunday as the first day of the week

B) It sets Monday as the first day of the week

C) It throws an error

D) It has no effect

20.What is the correct syntax to print a calendar for December 2025 using calendar.prmonth()?

A) calendar.prmonth(2025, 12)

B) calendar.prmonth(12, 2025)

C) calendar.prmonth(2025)

D) calendar.prmonth(12)
21.Does calendar.timegm() handle daylight saving time (DST)?

A) Yes, it adjusts the timestamp according to DST

B) No, it uses UTC time and does not consider DST

C) Yes, it converts the time to DST time automatically

D) No, it only works with standard time

22.What is the effect of changing calendar.setfirstweekday(6)?

A) The calendar starts on Saturday

B) The calendar starts on Sunday

C) The calendar throws an error

D) It changes the month view

25How does calendar.prmonth() display months with fewer than 7 days?

A) It adjusts the output to fit the week format

B) It throws an error

C) It leaves empty spaces for the missing days

D) It prints a blank space for the entire month

26.What is the output of the following code?

import calendar calendar.prmonth(2024,

4)

A) Prints the calendar for April 2024 to the console

B) Returns the calendar as a string

C) Returns None

D) Throws an error

Answer: A (It prints the calendar to the console)


27.What does the following code do?

import calendar

calendar.setfirstweekday(6)

A) Sets the first day of the week to Sunday

B) Sets the first day of the week to Saturday

C) Prints the calendar for Sunday as the first weekday

D) Returns an error

28. What will this code return?

import calendar calendar.timegm((2024, 4, 1,

12, 0, 0, 0, 0, 0))

A) A datetime.date object

B) A Unix timestamp (integer)

C) A str representing the time

D) A tuple of the form (year, month, day)

Answer: B (It returns a Unix timestamp, an integer)

29. What is the output of the following code?

import calendar calendar.prmonth(2024,

2, w=5, l=2)

A) Prints February 2024 calendar with width 5 and 2 lines per week

B) Returns the calendar as a string with width 5 and 2 lines per week

C) Throws an error because w and l are not valid


D) Prints the calendar in the default format without any modifications

Answer: A (It prints the month with the specified width and line length) Answer: B (It returns an integer
representing the weekday, where Monday = 0 and Sunday = 6)

30. What does this code do?

import calendar calendar.prmonth(2024,

12)

A) Prints the calendar for December 2024

B) Returns the calendar for December 2024

C) Throws an error

D) Prints the calendar for January 2024

Answer: A (It prints the calendar for December 2024)

31.What does calendar.setfirstweekday(3) do?

import calendar calendar.setfirstweekday(3)

A) Sets the first day of the week to Wednesday

B) Sets the first day of the week to Sunday

C) Throws an error because the valid range is 0–6

D) Sets the first day of the week to Tuesday

Answer: A (It sets Wednesday as the first day of the week)

32.What will the following code output?

import calendar print(calendar.monthrange(2024,

4))

A) (0, 30)
B) (0, 31)

C) (6, 30)

D) (6, 31)

Answer: A (It returns a tuple: (first weekday of the month, number of days in the month))

33. What is the return type of the following code?

import calendar calendar.monthcalendar(2024,

4)

A) str

B) list

C) tuple

D) NoneType

Answer: B (It returns a list of weeks, each containing a list of day numbers)

34.What is the purpose of calendar.timegm()?

import calendar calendar.timegm((2024, 4, 1,

12, 0, 0, 0, 0, 0))

A) Converts a tuple representing UTC to a Unix timestamp

B) Converts a date to a datetime.date object

C) Converts a Unix timestamp to a string

D) Converts a string to a date object

Answer: A (It converts a time tuple to a Unix timestamp)

35.What will this code return?


import calendar calendar.isleap(2024)

A) True

B) False

C) None

D) 1

Answer: A (2024 is a leap year, so it returns True)

35.What will this code return?

import calendar calendar.firstweekday()

A) 0

B) 1

C) 6

D) None

2300080412_Devisree:
Type of modules:
calendar.calendar(year, w=2, l=1, c=6, m=3) / calendar.firstweekday
Time Module Questions
1. How do you get the current time in seconds since the epoch using the time module?

A) time.localtime()

B) time.strftime("%Y-%m-%d %H:%M:%S")

C) time.time()

D) time.sleep(1)

answer -c

2. What function in the time module allows you to pause execution for a few seconds?

A) time.delay()

B) time.sleep(n)

C) time.pause(n)

D) time.wait(n)

answer - b

3. How can you format the current local time as "YYYY-MM-DD HH:MM:SS" using the time module?

A) time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())

B) time.format("%Y-%m-%d %H:%M:%S")

C) time.convert("%Y-%m-%d %H:%M:%S")

D) time.get_time("%Y-%m-%d %H:%M:%S")

answer -a

4. What is the difference between time.time() and time.localtime()?

A) time.time() gives the local time, and time.localtime() gives epoch time

B) time.time() returns a struct_time, while time.localtime() returns seconds

C) time.time() returns the current timestamp, while time.localtime() converts it into a readable struct_time

D) They are both the same function


answer - c

5. How can you measure the execution time of a function using the time module?

A) time.measure()

B) time.clock()

C) time.time() before and after execution, then find the difference

D) time.run_time()

answer - c

Calendar Module Questions

6. How do you print a calendar for July 2025 using the calendar module?

A) calendar.show(2025, 7)

B) calendar.display(2025, 7)

C) calendar.month(2025, 7)

D) calendar.print_month(2025, 7)

answer - c

7. How can you check if a given year is a leap year using Python?

A) calendar.check_leap(2024)

B) calendar.isleap(2024)

C) calendar.leap_year(2024)

D) calendar.year_is_leap(2024)

answer - b

8. What function returns the first weekday and the number of days in a given month?

A) calendar.getmonth(2025, 7)

B) calendar.monthrange(2025, 7)
C) calendar.weekday(2025, 7, 1)

D) calendar.first_weekday(2025, 7)

answer - b

9. How do you get the number of leap years between 2000 and 2025 using the calendar module?

A) calendar.count_leaps(2000, 2025)

B) calendar.leap_count(2000, 2025)

C) calendar.leapdays(2000, 2025)

D) calendar.get_leaps(2000, 2025)

answer -d

10. What function prints the entire calendar for a given year?

A) calendar.full_year(2025)

B) calendar.display(2025)

C) calendar.show_calendar(2025)

D) calendar.calendar(2025)

answer – d

2300090376_ACHYUTA JASHVAN:
Type of modules:
calendar.isleap/calendar.leapdays(year1, year2)
Which function in the calendar module checks if a given year is a leap year?

a) isleap()

b) leapyear()

c) is_leap()

d) checkleap()

Answer: a) isleap()

What will calendar.isleap(2024) return?

a) True

b) False

c) None

d) Error

Answer: a) True

What does calendar.leapdays(2000, 2021) return?

a) 5

b) 6

c) 7

d) 8

Answer: b) 6

Which statement about the calendar.leapdays(year1, year2) function is correct?

a) It counts leap years between year1 and year2, both inclusive.

b) It counts leap years between year1 and year2, excluding year2.

c) It only works for years greater than 1900.

d) It raises an error if year1 is greater than year2.

Answer: b) It counts leap years between year1 and year2, excluding year2.

Which of the following years is a leap year?


a) 1900

b) 2000

c) 2100

d) 2200

Answer: b) 2000

What will calendar.isleap(2100) return?

a) True

b) False

c) None

d) Error

Answer: b) False

How many leap days are there between 2010 and 2025 (using calendar.leapdays(2010, 2025)) ?

a) 3

b) 4

c) 5

d) 6

Answer: b) 4

Which of the following years are NOT leap years?

a) 2012

b) 2016

c) 2018

d) 2020

Answer: c) 2018

What is the output of calendar.isleap(2023)?

a) True

b) False

c) None

d) Error

Answer: b) False

You might also like