0

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?

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

5 Comments

@JasonSperske, yes it would, but Guido prefers list comprehensions and I'm not going to argue with him.
Is the con readability or some shortsightedness in the map() function?
Hi I don't get this part of the code: [float(part) for part in input
@TimTimmy, look at docs.python.org/2/tutorial/…. Instead of using a range as in the example, I'm using the results of split which returns strings in a list.
I've been working my way through The Little Schemer so this in really fascinating to me. Thanks for the link :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.