forked from nlohmann/json
-
Notifications
You must be signed in to change notification settings - Fork 0
test c #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
joyfaker
wants to merge
1
commit into
develop
Choose a base branch
from
20251225
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
test c #6
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| import time | ||
|
|
||
| # 1. 逻辑/语法错误:函数定义缺少冒号,且缩进不规范 | ||
| def calculate_discount(price, discount) | ||
| final_price = price * (1 - discount) | ||
| return final_price # 缩进错误 | ||
|
|
||
| # 2. 陷阱:使用可变对象(列表)作为默认参数 | ||
| def add_item_to_cart(item, cart=[]): | ||
| cart.append(item) | ||
| return cart | ||
|
|
||
| class User: | ||
| # 3. 拼写错误:初始化方法写成了 _init_ 而不是 __init__ | ||
| def _init_(self, name, age): | ||
| self.name = name | ||
| self.age = age | ||
|
|
||
| def greet(self): | ||
| # 4. 类型错误:尝试将字符串和整数直接连接 | ||
| print("Hello, I am " + self.name + " and I am " + self.age + " years old.") | ||
|
|
||
| def main(): | ||
| print("Welcome to the shop!") | ||
|
|
||
| # 5. 逻辑错误:运算符误用 (^ 在 Python 中是异或,不是幂运算) | ||
| square_area = 10 ^ 2 | ||
| print(f"Area calculation check: {square_area}") | ||
|
|
||
| # 6. 语法错误:在 if 条件中使用了赋值运算符 (=) 而不是比较运算符 (==) | ||
| user_input = "yes" | ||
| if user_input = "yes": | ||
| print("User agreed.") | ||
|
|
||
| # 7. 运行时错误:IndexError (索引越界) | ||
| items = ["Apple", "Banana", "Orange"] | ||
| for i in range(len(items) + 1): | ||
| print(f"Item {i}: {items[i]}") | ||
|
|
||
| # 8. 运行时错误:ZeroDivisionError (除以零) | ||
| count = 0 | ||
| total = 100 | ||
| average = total / count | ||
| print("Average: " + average) | ||
|
|
||
| # 9. 拼写错误:name 变量拼写错误 | ||
| if __name__ == "__main__": | ||
| mian() | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
发现 2 个问题: