#Python 2/3, 252 249 bytes
Python 2/3, 252 249 bytes
import re,math;i=[float(x)if re.match('[\d.]+',x)else x for x in re.sys.stdin.readline().split()]
for o in[0,[4,3][i[0]<'d']]:
w=i[o+1]*i[o+2]*i[o+3]
if i[o]<'d':w*=3.14*i[o+1]/i[o+3]
if i[o]>'s':w*=.5
a=a/w if o else w
print(math.ceil(a)*i[-1])
Usage Examples:
$ echo 'triangle 10 12.25 3 circle 5 2.2 5' | python stack_codegolf_54454.py
10.0
$ echo 'triangle 5 87.3 20001 rectangle 5.14 2 105.623 0.2' | python stack_codegolf_54454.py
804.2
The Python 2 only and Python 3 only versions are only different in how they receive input; raw_input()
for Python 2 and input()
for Python 3, as opposed to re.sys.stdin.readline()
for the Python2/3 version.
Python 2, 240 237 bytes
import re,math;i=[float(x)if re.match('[\d.]+',x)else x for x in raw_input().split()]
for o in[0,[4,3][i[0]<'d']]:
w=i[o+1]*i[o+2]*i[o+3]
if i[o]<'d':w*=3.14*i[o+1]/i[o+3]
if i[o]>'s':w*=.5
a=a/w if o else w
print(math.ceil(a)*i[-1])
Python 3, 236 233 bytes
import re,math;i=[float(x)if re.match('[\d.]+',x)else x for x in input().split()]
for o in[0,[4,3][i[0]<'d']]:
w=i[o+1]*i[o+2]*i[o+3]
if i[o]<'d':w*=3.14*i[o+1]/i[o+3]
if i[o]>'s':w*=.5
a=a/w if o else w
print(math.ceil(a)*i[-1])
Changes:
Changed for o in[0,3if i[0]<'d'else 4]:
to for o in[0,[4,3][i[0]<'d']]:
. Thanks to Vioz for the inspiration :).