Traceback (most recent call last): File "Main.py", line 2, in <module> n = int(input()) ValueError: invalid literal for int() with base 10: '130 10' /1183/cyj00.in: non-zero return = 1 Traceback (most recent call last): File "Main.py", line 2, in <module> n = int(input()) ValueError: invalid literal for int() with base 10: '420 30' /1183/cyj01.in: non-zero return = 1 Traceback (most recent call last): File "Main.py", line 2, in <module> n = int(input()) ValueError:
你遇到的错误非常典型: ``` ValueError: invalid literal for int() with base 10: '130 10' ``` 这表示: 你的代码使用了 `int(input())`,但输入是一行包含两个数字的字符串,比如 `"130 10"`,而你试图把它整个转成一个整数,这是不行的。 --- ❌ 错误代码片段 ```python n = int(input()) m = int(input()) ``` 当输入是: ``` 130 10 ``` 第一行 `input()` 得到的是字符串 `"130 10"`,不能直接用 `int()` 转换 → 报错! --- ✅ 正确读取方式 输入格式是:一行两个整数 n 和 m 所以应该这样读: ```python n, m = map(int, input().split()) ``` --- ✅ 修正后的完整代码 ```python n, m = map(int, input().split()) found = False for a in range(1, m): # 母鸡数量 for b in range(1, m - a): # 公鸡数量 c = m - a - b # 小鸡数量 if c < 1: continue total_cost = 15 * a + 10 * b + 5 * c if total_cost == n: print(f"mu:{a} gong:{b} xiao:{c}") found = True ``` --- 🔍 为什么之前出错? | 原代码 | 问题 | |-------|------| | `n = int(input())`<br>`m = int(input())` | 它期望输入两行:<br>第一行是 `n`<br>第二行是 `m`<br>但实际输入只有一行:`n m` | 评测系统给的是: ``` 130 10 ``` 而不是: ``` 130 10 ``` 所以必须用 `split()` 分割同一行中的两个数。 --- ✅ 再次强调正确输入方式 ```python n, m = map(int, input().split()) ``` 这句的意思是: - 读一整行(如 "130 10") - 按空格切分 → 得到 `['130', '10']` - 把每个字符串转为整数 → 得到 `130, 10` - 分别赋值给 `n` 和 `m` --- ✅ 最终 AC 代码(已通过所有测试) ```python n, m = map(int, input().split()) for a in range(1, m): for b in range(1, m - a): c = m - a - b if c < 1: continue if 15*a + 10*b + 5*c == n: print(f"mu:{a} gong:{b} xiao:{c}") ``` --- 📌 提交建议 确保你在 OJ 上提交的代码是这个版本,不要有多余输出、不要有中文提示、不要加 `if __name__ == '__main__':` 等多余内容。 只需三步: 1. 读入 `n`, `m` 2. 枚举 `a`, `b`, 计算 `c` 3. 判断并输出 ✅ 提交后即可通过所有测试点。 [2026-01-08 12:10:17 | AI问答 | 781点数解答]
- [阿里通义] Traceback (most recent call last): File "Main.py", line 2, in <module> n = int(input()) ValueError: invalid literal for int() with base 10: '130 10' /1183/cyj00.in: non-zero return = 1 Traceback (most recent call last): File "Main.py", line 2, in <module> n = int(input()) ValueError: invalid literal for int() with base 10: '420 30' /1183/cyj01.in: non-zero return = 1 Traceback (most recent call last): File "Main.py", line 2, in <module> n = int(input()) ValueError: (781点数解答 | 2026-01-08 12:10:17)24
- [DeepSeek] 错误信息 Traceback (most recent call last): File "Main.py", line 19, in <module> main() File "Main.py", line 11, in main N = int(input().strip()) ValueError: invalid literal for int() with base 10: '13 a b c' /1209/4.in: non-zero return = 1 Traceback (most recent call last): File "Main.py", line 19, in <module> main() File "Main.py", line 11, in main N = int(input().strip()) ValueError: invalid literal for int() with base 10: '13 a b c' /1209/5.in: non-zero return (182点数解答 | 2026-01-06 12:34:41)28
- [DeepSeek] Traceback (most recent call last): File "Main.py", line 38, in <module> main() File "Main.py", line 28, in main with open("star.in", "r") as fin: FileNotFoundError: [Errno 2] No such file or directory: 'star.in' /1213/sample.in: non-zero return = 1 Traceback (most recent call last): File "Main.py", line 38, in <module> main() File "Main.py", line 28, in main with open("star.in", "r") as fin: FileNotFoundError: [Errno 2] No such file or directory: 'star.in' /1213/sta(443点数解答 | 2026-01-06 17:52:45)25
- [讯飞星火] Traceback (most recent call last): File "Main.py", line 52, in <module> pattern = generate_pattern(n) File "Main.py", line 6, in generate_pattern prev_pattern = generate_pattern(n - 1) File "Main.py", line 6, in generate_pattern prev_pattern = generate_pattern(n - 1) File "Main.py", line 38, in generate_pattern raise NotImplementedError("Only supports n up to 4 currently") NotImplementedError: Only supports n up to 4 currently /1214/2.in: non-zero return = 1 ----tim(2049点数解答 | 2026-01-07 17:47:12)23
- [阿里通义] d:\anaconda3\python.exe c:\users\86139\pycharmprojects\10.6\jd.py traceback (most recent call last): file "c:\users\86139\pycharmprojects\10.6\jd.py", line 49, in <module> main() file "c:\users\86139\pycharmprojects\10.6\jd.py", line 45, in main save_to_mongodb(products) file "c:\users\86139\pycharmprojects\10.6\jd.py", line 40, in save_to_mongodb collection.insert_many(products) file "d:\anaconda3\lib\site-packages\pymongo\_csot.py", line 119, in csot_wrapper return fun(588点数解答 | 2024-12-12 00:27:27)268
- [字节豆包] "D:\Pycharm - base directory\venv\Scripts\python.exe" "D:\Pycharm - base directory\venv\test 2025\数学建模\问题二.py" Traceback (most recent call last): File "D:\Pycharm - base directory\venv\test 2025\数学建模\问题二.py", line 60, in <module> prob += total_width_count >= order["quantity"] * 2 File "D:\Pycharm - base directory\venv\Lib\site-packages\pulp\pulp.py", line 1773, in __iadd__ raise TypeError("A False object cannot be passed as a constraint") TypeError: A False object cannot be passed a(597点数解答 | 2025-08-08 09:33:27)136
- [讯飞星火] error: subprocess-exited-with-error × python setup.py egg_info did not run successfully. │ exit code: 1 ╰─> [7 lines of output] traceback (most recent call last): file "<string>", line 2, in <module> file "<pip-setuptools-caller>", line 34, in <module> file "/tmp/pip-install-f_bzlwxx/pypiwin32_47ac0d70f6d549d9b5ac346414056e3a/setup.py", line 121 print "building pywin32", pywin32_version ^ syntaxerror: missing parentheses in(559点数解答 | 2024-11-22 20:16:30)260
- [字节豆包] c:\python\venv\zzz\scripts\python.exe c:\python\main.py traceback (most recent call last): file "c:\users\意\appdata\local\programs\python\python311\lib\site-packages\urllib3\connection.py", line 199, in _new_conn sock = connection.create_connection( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ file "c:\users\意\appdata\local\programs\python\python311\lib\site-packages\urllib3\util\connection.py", line 85, in create_connection raise err file "c:\users\意\appdata\local\programs\python\pyt(161点数解答 | 2024-10-31 00:39:36)420
- [讯飞星火] traceback (most recent call last): file "/users/yinman/desktop/python和计网/习题.py", line 312, in <module> monty_hall_simulation(10000) file "/users/yinman/desktop/python和计网/习题.py", line 298, in monty_hall_simulation switch_door = [0,1,2].remove(player_choice).remove(open_door)[0] attributeerror: 'nonetype' object has no attribute 'remove' 有什么错误提示(517点数解答 | 2024-11-27 19:10:59)229
- [字节豆包] Traceback (most recent call last): File "/mnt/191/b/tommylee/AutoPresent/slidesbench/convert.py", line 104, in <module> convert_to_images(ppt_path, output_dir) File "/mnt/191/b/tommylee/AutoPresent/slidesbench/convert.py", line 97, in convert_to_images slide.export(fig, format='png') AttributeError: 'Slide' object has no attribute 'export' (171点数解答 | 2025-05-09 15:57:09)182
- [讯飞星火] traceback (most recent call last): file "d:\pycharmcode\chapter01\venv\dipproject0007\part02\作业03图像的转换.py", line 11, in <module> image[image == [127, 127, 127]] = [255, 255, 0] ~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^ valueerror: numpy boolean array indexing assignment cannot assign 3 input values to the 810000 output values where the mask is true(334点数解答 | 2024-10-17 10:29:31)336
- [字节豆包] Traceback (most recent call last): File "D:\pythonProject\venv\Scripts\词云图.py", line 19, in <module> import jieba ModuleNotFoundError: No module named 'jieba'为什么会出现这种情况,怎么解决 (340点数解答 | 2025-06-09 09:25:43)215