Reputation: 11
How can I take multiple user input data for specific data type?
For example in PYTHON 3.xx:
int(input(varl)) # or
float(input(varl)) # for to take only one single input
varl0 = [varl0 for varl0 in input("Enter multiple values: ").split()]
Similarly for taking multiple variables (specific data type) input from the user:
Upvotes: 0
Views: 63
Reputation: 4980
You are almost there. Just try this one for int
numbers (as a integer list):
If you want float
- then just change int
to float
in the List Compression.
nums = [int(num) for num in input("Enter multiple integer numbers: ").split()] # convert string to int by `int(num)`
Enter multiple integer numbers: 1 2 3 4 5
# Output after running:
print(nums) # [1, 2, 3, 4, 5]
Upvotes: 2