selfteaching / selfteaching/selfteaching-python-camp

Day04 关于“计算器”的思考路径和困惑

Open
#857 1 comment 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、用户输入”运算字符串(如4+2)";
2、计算机读取该”运算字符串“,而后进行运算;
3、输出结果。

二、落地
1、input可以用来帮我将用户的输入读入计算机;
2、Google让我找到了一个函数“eval“,它可以用来帮我做里面的运算。
3、问题到这里似乎没什么要做的,直接输入结果就可以了。

三、问题
可是我很快意识到:“用户的输入”可能是错的,比如”1/0“,以及其它许多类型的错误。在这样的局面下,计算器程序事实上是无法运行的。

Google让我了解到应该做”exception handling“,可是我写不出正确的“try-except”形式,于是,整个工作陷于“停滞”。

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

Start with the calculator flow described in the issue: reading an expression with input, evaluating it with eval, and handling inputs such as 1/0. Review Python's try-except guidance and test the listed examples interactively. Done means the calculator can report the described input errors instead of stopping.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli
Issue type
Feature
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.