Skip to main content
added 256 characters in body
Source Link
MrSmith42
  • 2.1k
  • 1
  • 14
  • 28

What about:

  1. using 10:00 as default:
  2. only check for weekend
  3. you might replace (str(day) in weekend) by (0 == str(day) %6) but it is harder to understand

Code:

def alarm_clock(day, vacation):
    weekend = "06"
    if vacation and (str(day) in weekend):
        return "off"
    else:
        if not (str(day) in weekend):
            return "7:00"
    return "10:00"

The bit more cryptic version:

def alarm_clock(day, vacation):
    if vacation and 0 == day % 6:
        return "off"
    else:
        if 0 != day % 6:
            return "7:00"
    return "10:00"

What about:

  1. using 10:00 as default:
  2. only check for weekend
  3. you might replace (str(day) in weekend) by (0 == str(day) %6) but it is harder to understand

Code:

def alarm_clock(day, vacation):
    weekend = "06"
    if vacation and (str(day) in weekend):
        return "off"
    else:
        if not (str(day) in weekend):
            return "7:00"
    return "10:00"

What about:

  1. using 10:00 as default:
  2. only check for weekend
  3. you might replace (str(day) in weekend) by (0 == day %6) but it is harder to understand

Code:

def alarm_clock(day, vacation):
    weekend = "06"
    if vacation and (str(day) in weekend):
        return "off"
    else:
        if not (str(day) in weekend):
            return "7:00"
    return "10:00"

The bit more cryptic version:

def alarm_clock(day, vacation):
    if vacation and 0 == day % 6:
        return "off"
    else:
        if 0 != day % 6:
            return "7:00"
    return "10:00"
Source Link
MrSmith42
  • 2.1k
  • 1
  • 14
  • 28

What about:

  1. using 10:00 as default:
  2. only check for weekend
  3. you might replace (str(day) in weekend) by (0 == str(day) %6) but it is harder to understand

Code:

def alarm_clock(day, vacation):
    weekend = "06"
    if vacation and (str(day) in weekend):
        return "off"
    else:
        if not (str(day) in weekend):
            return "7:00"
    return "10:00"