Nov-29-2017, 07:54 PM
I'm trying to make a programme that calculates a mathematical ratio problem. in order to do so i convert the 4 numbers the user enters into list elements, then i perform the operations on them. However, i have a problem with whitespace, how do i remove those in python? Here's my programme:
# !/usr/bin/python
# -*- coding: utf8 -*-
import math
def data_prosesering():
ratio = list(raw_input('ratio syfers: '))
r1 = float(ratio[0]) * float(ratio[1])
r2 = float(ratio[2]) * float(ratio[3])
a = r1/r2
print math.sqrt(a)
data_prosesering()First searched and tried to do something like this: d = [x.strip() for x in ratio]Then however i got stuck so i went searching for solutions again and finally got the idea of trying this:
pre_ratio = raw_input('ratio syfers: ')
pre_ratio.split()
ratio = list(pre_ratio)
print ratio #testing if this worksThis however didn't work either. Does anyone know how to solve this problem?Python version: 2.7
operating system: windows 8
