Reputation: 323
I want to make this program in Python 3.3.2 which asks you for the radius and height of a cylinder which you have to type in as radius
, height
Here is the current code:
if response=="vol":
radius = float(input("What is the radius and height of the cylinder? (e.g. 32, 15): "))
How should I change it? After that I will calculate its volume: V = hπr2 How will I do this with your method?
Upvotes: 0
Views: 966
Reputation: 308138
radius, height = [float(part) for part in input("What is the radius and height of the cylinder? (e.g. 32, 15): ").split(',')]
The split
splits the input at the comma into two parts; the for
is part of a list comprehension, which creates a list by applying the same action to each result.
Upvotes: 2