u/Opening-Ninja2064

Please help me!!!!!!!!! i couldn't solve this

my main code

import re



def main():
    time = convert(input("Hours: "))
    print(time)



def convert(s):


    if s := re.search(r"^(\d{1,2})(?::(\d{2}))? (AM|PM) to (\d{1,2})(?::(\d{2}))? (AM|PM)$", s, re.IGNORECASE):
        time = list(s.groups())


        if time[1] == None:
            time[1] = 0


        if time[4] == None:
            time[4] = 0


        if int(time[1]) >= 60 or int(time[4]) >= 60 or int(time[3]) > 12 or int(time[0]) > 12:
            raise ValueError
        if (time[5].upper() == "AM") and (time[3] == "12"):
            x_hour = 0
        elif time[5].upper() == "PM":
            if int(time[3]) == 12:
                x_hour = 12
            else:
                x_hour = int(time[3]) + 12
        else:
            x_hour = int(time[3])


        if time[2].upper() == "PM":
            if int(time[0]) == 12:
                y_hour = 12
            else:
                y_hour = int(time[0]) + 12
        elif (time[2].upper() == "AM") and (time[0] == "12"):
            y_hour = 0
        else:
            y_hour = int(time[0])






        return f"{y_hour:02}:{int(time[1]):02} to {x_hour:02}:{int(time[4]):02}"


    raise ValueError


if __name__ == "__main__":
    main()

my pytest code

from working import convert
import pytest



def test_convert():
    assert convert("9 am to 5 pm") == "09:00 to 17:00"
    assert convert("4 pm to 5 am") == "16:00 to 05:00"
    assert convert("12:00 AM to 12:00 PM") == "00:00 to 12:00"
    assert convert("12 AM to 12 PM") == "00:00 to 12:00"
    assert convert("8:00 PM to 8:00 AM") == "20:00 to 08:00"
    assert convert("11 am to 11 pm") == "11:00 to 23:00"
    assert convert("3 am to 11:30 pm") == "03:00 to 23:30"


def test_1():


    with pytest.raises(ValueError):
        convert("16 pm to 5 am")


    with pytest.raises(ValueError):
        convert("8:60 AM to 4:60 PM")
    with pytest.raises(ValueError):
        convert("9AM to 5PM")
    with pytest.raises(ValueError):
        convert("09:00 to 17:00")
    with pytest.raises(ValueError):
        convert("10:7 AM - 5:1 PM")
    with pytest.raises(ValueError):
        convert("09 AM to 5:001 PM")
    with pytest.raises(ValueError):
        convert("16 pm to 5 am")


def test_2():


    with pytest.raises(ValueError):
        convert("11:60 am to 5:60 pm")
    with pytest.raises(ValueError):
        convert("9 am - 5 pm")

check50 cs50/problems/2022/python/working

Connecting.......

Authenticating...

Verifying......

Preparing.....

Uploading........

Waiting for results......................

Results for cs50/problems/2022/python/working generated by check50 v4.0.0.dev0

:) working.py and test_working.py exist

:) working.py does not import libraries other than sys and re

:) working.py converts "9 AM to 5 PM" to "09:00 to 17:00"

:) working.py converts "9:00 AM to 5:00 PM" to "09:00 to 17:00"

:) working.py converts "8 PM to 8 AM" to "20:00 to 08:00"

:) working.py converts "8:00 PM to 8:00 AM" to "20:00 to 08:00"

:) working.py converts "12 AM to 12 PM" to "00:00 to 12:00"

:) working.py converts "12:00 AM to 12:00 PM" to "00:00 to 12:00"

:) working.py raises ValueError when given "8:60 AM to 4:60 PM"

:) working.py raises ValueError when given "9AM to 5PM"

:) working.py raises ValueError when given "09 AM to 5:001 PM"

:) working.py raises ValueError when given "09:00 to 17:00"

:) working.py raises ValueError when given "9 AM - 5 PM"

:) working.py raises ValueError when given "10:7 AM - 5:1 PM"

:( correct working.py passes all test_working checks

expected exit code 0, not 1

:| test_working.py catches working.py printing hours off by one

can't check until a frown turns upside down

:| test_working.py catches working.py printing minutes off by five

can't check until a frown turns upside down

:| test_working.py catches working.py not raising ValueError when user omits " to "

can't check until a frown turns upside down

:| test_working.py catches working.py not raising ValueError for out-of-range times

can't check until a frown turns upside down

To see more detailed results go to https://submit.cs50.io/check50/3a0981d4c30c738a309e4450c6ae0f4ca1f60497

working/ $

reddit.com
u/Opening-Ninja2064 — 1 day ago
▲ 0 r/cs50

Please help me!!!!!!!!! i couldn't solve this

my working 9 to 5 python code

import re



def main():
    time = convert(input("Hours: "))
    print(time)



def convert(s):


    if s := re.search(r"^(\d{1,2})(?::(\d{2}))? (AM|PM) to (\d{1,2})(?::(\d{2}))? (AM|PM)$", s, re.IGNORECASE):
        time = list(s.groups())


        if time[1] == None:
            time[1] = 0


        if time[4] == None:
            time[4] = 0


        if int(time[1]) >= 60 or int(time[4]) >= 60 or int(time[3]) > 12 or int(time[0]) > 12:
            raise ValueError
        if (time[5].upper() == "AM") and (time[3] == "12"):
            x_hour = 0
        elif time[5].upper() == "PM":
            if int(time[3]) == 12:
                x_hour = 12
            else:
                x_hour = int(time[3]) + 12
        else:
            x_hour = int(time[3])


        if time[2].upper() == "PM":
            if int(time[0]) == 12:
                y_hour = 12
            else:
                y_hour = int(time[0]) + 12
        elif (time[2].upper() == "AM") and (time[0] == "12"):
            y_hour = 0
        else:
            y_hour = int(time[0])






        return f"{y_hour:02}:{int(time[1]):02} to {x_hour:02}:{int(time[4]):02}"


    raise ValueError


if __name__ == "__main__":
    main()

my test_working file

from working import convert
import pytest



def test_convert():
    assert convert("9 am to 5 pm") == "09:00 to 17:00"
    assert convert("4 pm to 5 am") == "16:00 to 05:00"
    assert convert("12:00 AM to 12:00 PM") == "00:00 to 12:00"
    assert convert("12 AM to 12 PM") == "00:00 to 12:00"
    assert convert("8:00 PM to 8:00 AM") == "20:00 to 08:00"
    assert convert("11 am to 11 pm") == "11:00 to 23:00"
    assert convert("3 am to 11:30 pm") == "03:00 to 23:30"


def test_1():


    with pytest.raises(ValueError):
        convert("16 pm to 5 am")


    with pytest.raises(ValueError):
        convert("8:60 AM to 4:60 PM")
    with pytest.raises(ValueError):
        convert("9AM to 5PM")
    with pytest.raises(ValueError):
        convert("09:00 to 17:00")
    with pytest.raises(ValueError):
        convert("10:7 AM - 5:1 PM")
    with pytest.raises(ValueError):
        convert("09 AM to 5:001 PM")
    with pytest.raises(ValueError):
        convert("16 pm to 5 am")


def test_2():


    with pytest.raises(ValueError):
        convert("11:60 am to 5:60 pm")
    with pytest.raises(ValueError):
        convert("9 am - 5 pm")

https://preview.redd.it/afvvvx7vb9wg1.png?width=931&format=png&auto=webp&s=f86a840edc5198a0e7e98777ab59bb1cfa5de2a9

reddit.com
u/Opening-Ninja2064 — 1 day ago