为所有大物1的py配置ipynb,但是均未经过测试

This commit is contained in:
SOR
2026-09-22 16:04:12 +08:00
parent af6d2bbc93
commit 664c80166b
24 changed files with 1893 additions and 3 deletions
+59
View File
@@ -0,0 +1,59 @@
from decimal import Decimal
def input_float(prompt, default=None):
"""输入一个浮点数值,支持默认值"""
while True:
try:
suffix = f" (默认 {default})" if default is not None else ""
val = input(f"{prompt}{suffix}: ").strip()
if not val and default is not None:
return float(default)
if not val:
continue
return float(val)
except Exception:
print(" 输入无效,请输入数字。")
def input_decimal(prompt, default=None):
"""输入一个 Decimal 值,支持默认值"""
while True:
try:
suffix = f" (默认 {default})" if default is not None else ""
val = input(f"{prompt}{suffix}: ").strip()
if not val and default is not None:
return Decimal(str(default))
if not val:
continue
return Decimal(val)
except Exception:
print(" 输入无效,请输入数字。")
def input_int(prompt, default=None):
"""输入一个整数,支持默认值"""
while True:
try:
suffix = f" (默认 {default})" if default is not None else ""
val = input(f"{prompt}{suffix}: ").strip()
if not val and default is not None:
return default
if not val:
continue
return int(val)
except Exception:
print(" 输入无效,请输入整数。")
def input_data_group(name, count, unit=""):
"""输入一组重复测量的数值"""
prompt_unit = f" (单位: {unit})" if unit else ""
print(f"\n请输入 {name} 的 {count} 次测量值{prompt_unit}:")
data = []
for i in range(count):
while True:
try:
val = input(f"第 {i+1} 次 = ").strip()
if not val: continue
data.append(Decimal(val))
break
except Exception:
print("输入无效,请输入数字。")
return data