Hi,
I'm getting WA for this problem, too. Similar to chaconnewuI assumed that it might be an issue of (too much) accuracy in python, since the only differences to an C++ Code I tried on IDEONE ocurred when the input figures were quite large.
This is my code:
""" Problem SPOJ 2524: Conversions (GNY07B) Short vers."""
import sys
def init_conversions():
conv = {
'kg': [2.2046, 'lb'], 'lb': [0.4536, 'kg'],
'l': [0.2642, 'g'], 'g': [3.7854, 'l']
}
return conv
def main():
cases = sys.stdin.read().split('\n')
conversions = init_conversions()
results = []
for i, line in enumerate(cases[1:]):
if line :
number, unit = line.split()
result = '%s %.4f %s' % (i + 1,
float(number) * (conversions[unit][0]),
conversions[unit][1])
results.append(result)
sys.stdout.writelines ('\n'.join(results))
sys.stdout.write('\n')
if __name__ == '__main__':
main()
Anyone seeing the mistake?
Regards
Daft