简体   繁体   English

如何同时要求浮点输入和整数?

[英]How can I ask for a float input and an integer at the same time?

I want to ask subjects to type in first a float number ( like 3.666) followed by an integer. 我想让受试者先输入一个浮点数(例如3.666),然后输入一个整数。 what i did is: 我所做的是:

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

and then converted 然后转换

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

It does not work-are there any suggestions? 它不起作用-有什么建议吗?

You have to scan them as a string, separate it by space as delimiter and then typecast them to their corresponding types. 您必须将它们扫描为字符串,以空格分隔作为定界符,然后将其类型转换为相应的类型。

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

Hope that helps :) 希望有帮助:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM