selfteaching / selfteaching/selfteaching-python-camp

Day08 对自学任务中作业1 的疑问

Open
#662 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
151
Forks
875
PR merge metrics
No merged PRs in 30d

Description

import re
def stats_text_en(text):
    '''1、使用字典(dict)统计text中每个英文单词出现的次数.
    2、添加类型检查,如果不是字符串类型为异常'''
    try:
        text + ""
    except ValueError as e:
       print(e)

    result = re.sub("[^A-Za-z]", " ", text.strip())
    d = {}    
    for x in result.split( ):
        if not x in d:
            d[x] = 1
        else:
            d[x] = d[x]+1
    return d

我的代码是用 try except,这样的话异常提示是 TypeError: can only concatenate tuple (not "str") to tuple。不符合题目要求的ValueError错误,如果用raise的话,那提示错误信息就是自定义的啊,这符合作业要求吗?作业要求是包含完整的错误提示信息,自定义的提示信息也可以吗

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No repository file or test is named. Start by reading the Day08 self-study Task 1 wording and comparing it with Python's exception behavior; done means the expected exception type and whether custom messages satisfy the stated complete-error-message requirement are explicitly clarified.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
content, documentation
Issue type
Documentation
Difficulty
1/5
Estimated time
Under an hour
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.