gpt4 book ai didi

python - 如何同时请求浮点输入和整数?

转载 作者:太空宇宙 更新时间:2023-11-03 17:19:46 26 4
gpt4 key购买 nike

我想要求受试者首先输入一个 float (如 3.666),然后输入一个整数。我所做的是:

x,y = input ( " Please enter two numbers"). split () 

然后转换

x,y =[ float (x), int (y)] 

它不起作用 - 有什么建议吗?

最佳答案

您必须将它们作为字符串扫描,用空格作为分隔符将其分隔,然后将它们转换为相应的类型。

s = raw_input("Please enter two numbers: ")
x,y = s.split(" ")
x = float(x)
y = int(y)

希望有帮助:)

关于python - 如何同时请求浮点输入和整数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33288815/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com