Jan-03-2018, 12:24 PM
In this programme i'm trying to solve a mathematical ratio problem, then calculate the squareroot, however, whenever i try to give it input like this: 2.5, it throws out the following error:
Error:ValueError: could not convert string to float: .
, obviously it doesn't recognise the "." as a number. Here's the complete code:# !/usr/bin/python # -*- coding: utf8 -*- import math def data_processing(): ratio = list(raw_input('ratio numbers: ').replace(' ', '')) r1 = float(ratio[0]) * float(ratio[1]) r2 = float(ratio[2]) * float(ratio[3]) a = r1/r2 print math.sqrt(a) data_processing()How can i get the float() function to recognise a number like this: 2.5 as a floating point number with a decimal point instead of a group of numbers with the string "."? what is the easiest way to fix this? thanks