main.py
Costs 1 credit
加载编辑器中...
输出 Output执行成功
[错误提示] 检测到中文全角符号(如 ( ) , : ;),Python 语法可能无法解析。 请改成英文半角符号:( ) , : ;
Terminal (Simulated)Install commands are simulated only, no real network requests
$
Step 1: 数据采集与转换
input() 函数拿到的结果永远是“文本”(字符串)。要进行加减法,必须先用 float() 将它变成数字。
底层逻辑:
用户输入先进入字符串缓冲区,不会自动推断为数值。
不做类型转换就做运算,结果会变成文本拼接而非数学计算。
用户输入先进入字符串缓冲区,不会自动推断为数值。
不做类型转换就做运算,结果会变成文本拼接而非数学计算。
你的任务:
- 使用
num1 = float(input("请输入第一个数: "))获取第一个数 - 同理获取第二个数并赋值给
num2 - 输出
num1 + num2的结果
常见误区:
直接用
直接用
input() 的结果相加会变成字符串拼接(如 "1"+"2" -> "12")。
Self-Check List
- 获取输入
- 进行类型转换
- 执行基础运算
Transfer Template
num1 = float(input("Number 1: "))
num2 = float(input("Number 2: "))After completing this step, you should be able to independently explain and reproduce this concept, then apply it to similar problems.