How to write a python script, that converts a string format number into 'real' number: integer, float.

0 Robert Trumpet · September 18, 2015
 I need to implement python built-in type convert function: 


The code should convert the following 3 strings into real values:
   (1) "7343345"
   (2) "-87634"
   (3) "98.783"


   What python functions are not allowed:
1.  the type convert function itself: int(), float()


In other words....
Define a function, that takes a string format number as input, and return the number itself. 
e.g. def stringToNumber(str):
         #your code here
           return number

Post a Reply

Replies

- page 2
Oldest  Newest  Rating
0 Halcyon Abraham Ramirez · October 13, 2015
ugh doesn't isdigit return a boolean?

and if you do this


def stringToNumber(str):

        return str.replace("'", "")






print(type(stringToNumber("7343345")))



output is:



so it wasn't converted :/

and isdigit() returns a boolean there is no actual conversion :/
0 Abdullah Sukkar · October 13, 2015
sir , 
i want them to come down each other and every line starts from the same start point not like this way :
127.90 
  3465.15 
  3.78 
  264.82 
  88.08
  • 1
  • 2

Python

107,048 followers
About

This section is all about snakes! Just kidding.

Links
Moderators
Bucky Roberts Administrator