← 返回题库
初级

实现屏幕分辨率规格校验

未完成
初级参考 完整示例代码供参考,建议自己理解后重新输入
def solve():
    from pyodide.http import open_url
    from io import StringIO
    import pandas as pd
    st_csv = open_url("https://data.zuihe.com/dbd/ms-adlift/state_00/screen_types.csv").read()
    screen_types = pd.read_csv(StringIO(st_csv))
    VALID_RES = {'1920x1080','1280x720','1080x1920','720x1280'}
    def validate(res, orientation):
        w, h = map(int, res.split('x'))
        expected = 'landscape' if w > h else 'portrait'
        return res in VALID_RES, orientation == expected, expected
    print("Screen type validation:")
    for _, row in screen_types.iterrows():
        res_ok, orient_ok, expected = validate(row['resolution'], row['orientation'])
        status = 'OK' if res_ok and orient_ok else 'FAIL'
        print("  "+row['model']+": "+row['resolution']+" "+row['orientation']+" expected="+expected+" -> "+status)

示例

输入
solve()
期望输出
Screen type validation:
  LCD-1080P-H: 1920x1080 landscape expected=landscape -> OK
  LCD-720P-H: 1280x720 landscape expected=landscape -> OK
  LCD-1080P-V: 1080x1920 portrait expected=portrait -> OK
  LCD-720P-V: 720x1280 portrait expected=portrait -> OK
Python 代码 🔒 登录后使用
🔒

登录后即可练习

注册免费账号,在浏览器中直接运行 Python 代码