Skip to main content
Stack Overflow
  1. About
  2. For Teams

Return to Question

added 14 characters in body
Source Link
user15801675
user15801675

Given a day of the week encoded as 0=Sun, 1=Mon, 2=Tue, ...6=Sat0=Sun, 1=Mon, 2=Tue, ...6=Sat, and a booleanboolean indicating if we are on vacation, return a string of the form "7:00" indicating when the alarm clock should ring.

Weekdays, the alarm should be "7:00" and on the weekend it should be "10:00". Unless we are on vacation -- then on weekdays it should be "10:00" and weekends it should be "off"

def alarm_clock(day, vacation):
 if not vacation and 1<=day<=5:
 return "7:00"
 if not vacation and day==0 or day==6:
 return "10:00"
 if vacation and 1<=day<=5:
 return "10:00"
 if vacation and day==0 or day==6:
 return "off"

Why does alarm_clock(6, False) → '10:00'alarm_clock(6, False) → '10:00' but alarm_clock(6, True) → '10:00'alarm_clock(6, True) → '10:00' instead of 'off''off'?

I know the correct answer but I'm still confused to why my initial logic is off.

Given a day of the week encoded as 0=Sun, 1=Mon, 2=Tue, ...6=Sat, and a boolean indicating if we are on vacation, return a string of the form "7:00" indicating when the alarm clock should ring. Weekdays, the alarm should be "7:00" and on the weekend it should be "10:00". Unless we are on vacation -- then on weekdays it should be "10:00" and weekends it should be "off"

def alarm_clock(day, vacation):
 if not vacation and 1<=day<=5:
 return "7:00"
 if not vacation and day==0 or day==6:
 return "10:00"
 if vacation and 1<=day<=5:
 return "10:00"
 if vacation and day==0 or day==6:
 return "off"

Why does alarm_clock(6, False) → '10:00' but alarm_clock(6, True) → '10:00' instead of 'off'?

I know the correct answer but I'm still confused to why my initial logic is off.

Given a day of the week encoded as 0=Sun, 1=Mon, 2=Tue, ...6=Sat, and a boolean indicating if we are on vacation, return a string of the form "7:00" indicating when the alarm clock should ring.

Weekdays, the alarm should be "7:00" and on the weekend it should be "10:00". Unless we are on vacation -- then on weekdays it should be "10:00" and weekends it should be "off"

def alarm_clock(day, vacation):
 if not vacation and 1<=day<=5:
 return "7:00"
 if not vacation and day==0 or day==6:
 return "10:00"
 if vacation and 1<=day<=5:
 return "10:00"
 if vacation and day==0 or day==6:
 return "off"

Why does alarm_clock(6, False) → '10:00' but alarm_clock(6, True) → '10:00' instead of 'off'?

I know the correct answer but I'm still confused to why my initial logic is off.

Source Link

Why does this function return a different value?

Given a day of the week encoded as 0=Sun, 1=Mon, 2=Tue, ...6=Sat, and a boolean indicating if we are on vacation, return a string of the form "7:00" indicating when the alarm clock should ring. Weekdays, the alarm should be "7:00" and on the weekend it should be "10:00". Unless we are on vacation -- then on weekdays it should be "10:00" and weekends it should be "off"

def alarm_clock(day, vacation):
 if not vacation and 1<=day<=5:
 return "7:00"
 if not vacation and day==0 or day==6:
 return "10:00"
 if vacation and 1<=day<=5:
 return "10:00"
 if vacation and day==0 or day==6:
 return "off"

Why does alarm_clock(6, False) → '10:00' but alarm_clock(6, True) → '10:00' instead of 'off'?

I know the correct answer but I'm still confused to why my initial logic is off.

lang-py

AltStyle によって変換されたページ (->オリジナル) /