python - 为什么我的数据在使用拆分功能时没有转换为浮点类型。#python3
问题描述
u,p,k = float(input(" enter the values of viscoity, pressure , prmeability")).split(",")
l,A = int(input("enter the vaues of length and area").split(" "))
def flow_rate(u,p,k,l,A):
Q=k* A * p/l*u
print(f"the Q is {Q}")
flow_rate(u,p,k,l,A)
解决方案
您在第一行中所做的是获取整个字符串,例如“3.5,5.6,9”,并尝试将其转换为浮点数,然后将其分开。问题是python无法将3个数字和逗号的字符串转换为float。你可以做的是首先拆分字符串,然后将每个元素转换为浮点数,如下所示:
u, p, k = map(float, input("Enter the values of viscosity, pressure, and permeability: ").split(", ")
# I changed the split separator so the input can be prettier ;)
对第二行应用相同的逻辑
推荐阅读
- python - macOS Catalina 10.15.5 上 psycopg2 的困难
- nexus - Nexus IQ + Angular 10 如何按照 IQ 的建议更新 Angular 中的传递依赖项
- python - 从数据框在条形图顶部创建折线图时出错
- javascript - 在打开新元素之前使可点击元素关闭可见元素
- python - Python Web Scraping - 仅查找 n 个项目
- javascript - 输入年龄后有没有办法删除结果?
- python - Python requests.get 未在 html 文档中的标签之一中返回文本
- python - 使用beautifulsoup抓取时无法获取所有数据
- c# - 如何解决nuget包中依赖版本的冲突?
- arrays - 指针 - 意外输出