selfteaching / selfteaching/selfteaching-python-camp

Day08 关于Error Type及如何让后续程序继续运行

Open
#4,139 3 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

1、对于如何判断输入是否为str不清楚,后来采用加空字串的方法,但这样产品的异常其实是TypeError,而不是ValueError。但可以输出自定义的异常信息;
2、关于如让程度继续运行,如果不采用强制类型转换到 str 程序也会异常中断,不知是否可以采用 str 进行强制转换这样处理?(目前没有加入,期待老师和同学指导)

以下为代码部分:
try:
text = text_in + ''
except TypeError:
print("哎哟,程序需要输入字符串,请再次运行程序,并重新输入......")

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

The issue provides only an inline Python try/except snippet and names no repository file or test. First determine which Day08 lesson or example this question belongs to, then check the expected behavior for invalid input and continuing execution. Done means the lesson or example states the intended exception-handling behavior and gives a clear way to verify it.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
documentation
Issue type
Documentation
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
15/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.