-1

どのような形状の領域を見つけたいかを人に尋ねる「簡単な」方法を作成しようとしています。次に、入力に基づいて形状の面積を見つけます。Python 2.7.3 を使用しています。これが私がこれまでに持っているものです:

from math import pi
c = ""
r = ""
x = (input("Do you have a [r]ectangle or a [c]ircle? ")) # Answer with r or c
if x == "r":
    l = (int(input("What is the length of your rectangle? ")))
    w = (int(input("What is the width of your rectangle? ")))
    print( l * w )
elif x == "c":
    r = (int(input("What is the radius of your circle? ")))
    print( r ** 2 * pi)
else:
    print("Please enter request in lower case. ")
4

1 に答える 1

0
from math import pi
# use raw input (raw_input()) for the inputs... input() is essentially eval(input())
# this is how i would ask for input for a simple problem like this
x = (raw_input("Do you have a [r]ectangle or a [c]ircle? ")) # Answer with r or c
# use .lower() to allow upper or lowercase
if x.lower() == "r":
    l = (int(raw_input("What is the length of your rectangle? ")))
    w = (int(raw_input("What is the width of your rectangle? ")))
    print( l * w )
elif x.lower() == "c":
    r = (int(raw_input("What is the radius of your circle? ")))
    print( r ** 2 * pi)
else:
    print("You didn't enter r or c.")
于 2013-04-25T13:58:55.080 に答える