pythonchallenge_level2

level2

地址:http://www.pythonchallenge.com/pc/def/ocr.html
源码:git@code.aliyun.com:qianlizhixing12/PythonChallenge.git。
问题:找出页面源码一点提示注释中的稀有字符。

#!/usr/bin/env python3
# -*- coding:UTF-8 -*-

# Level 2

import urllib.request

url = "http://www.pythonchallenge.com/pc/def/ocr.html"
response = urllib.request.urlopen(url)
body = response.read()
response.close

import re

body = body.decode("utf8")
text = re.search("<!--\n%%(.|\s)+\n-->", body).group(0)
lisall = []
liscop = []

for x in text:
    if not x.isalpha():
        pass
    elif x not in lisall:
        lisall.append(x)
    elif x not in liscop:
        liscop.append(x)
    else:
        pass

lis = [x for x in lisall if x not in liscop]
print("Level 2:", ''.join(lis))
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
下列代码在输入能耗之后回车会直接输出最终结果无法输入CCM值,请改良下列代码。#include <stdio.h> // 定义各项标准的等级划分 #define CADR_LEVEL_1 350 #define CADR_LEVEL_2 450 #define CADR_LEVEL_3 600 #define NOISE_LEVEL_1 30 #define NOISE_LEVEL_2 40 #define NOISE_LEVEL_3 50 #define POWER_CONSUMPTION_LEVEL_1 0.025 #define POWER_CONSUMPTION_LEVEL_2 0.04 #define POWER_CONSUMPTION_LEVEL_3 0.07 #define CCM_LEVEL_1 10 #define CCM_LEVEL_2 13 #define CCM_LEVEL_3 16 // 定义评价函数 int evaluate(int cadr, int noise, int power_consumption, int ccm) { int cadr_level = 0, noise_level = 0, power_consumption_level = 0, ccm_level = 0; // 判断 CADR 级别 if (cadr >= CADR_LEVEL_3) { cadr_level = 3; } else if (cadr >= CADR_LEVEL_2) { cadr_level = 2; } else if (cadr >= CADR_LEVEL_1) { cadr_level = 1; } // 判断噪音级别 if (noise <= NOISE_LEVEL_1) { noise_level = 3; } else if (noise <= NOISE_LEVEL_2) { noise_level = 2; } else if (noise <= NOISE_LEVEL_3) { noise_level = 1; } // 判断能耗级别 if (power_consumption <= POWER_CONSUMPTION_LEVEL_1) { power_consumption_level = 3; } else if (power_consumption <= POWER_CONSUMPTION_LEVEL_2) { power_consumption_level = 2; } else if (power_consumption <= POWER_CONSUMPTION_LEVEL_3) { power_consumption_level = 1; } // 判断 CCM 级别 if (ccm >= CCM_LEVEL_3) { ccm_level = 3; } else if (ccm >= CCM_LEVEL_2) { ccm_level = 2; } else if (ccm >= CCM_LEVEL_1) { ccm_level = 1; } // 计算综合评价 int total_evaluation = cadr_level+noise_level + power_consumption_level + ccm_level; return total_evaluation; } int main() { int cadr,noise, power_consumption, ccm; // 读取各项参数值 printf("请输入 CADR 值:"); scanf("%d", &cadr); printf("请输入噪音值:"); scanf("%d", &noise); printf("请输入能耗值:"); scanf("%d", &power_consumption); printf("请输入 CCM 值:"); scanf("%d", &ccm); // 计算评价结果 int evaluation = evaluate(cadr,noise, power_consumption, ccm); printf("总评价等级为:%d\n", evaluation); return 0; }
最新发布
05-10

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值