Laurie
Laurie

Reputation: 153

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. 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?

Upvotes: 1

Views: 2799

Answers (1)

Laschet Jain
Laschet Jain

Reputation: 744

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 :)

Upvotes: 1

Related Questions