1 2 3 4 5 6 7 8 9 10 | # float(), round() print ( "Example: float, round" ) Pi_str = "3.14159" print ( "the value of pi is " + Pi_str + " which we have put in a string - Python has no clue it is a number." ) #proves Pi_str is a string or print would bomb Pi_num = float (Pi_str) #make our Pi string into a decimal number print ( "Pi_num is assigned float(Pi_str) so we can use it as a number" ) print ( "Lets round it to 3 decimal points using the round(number [,digits]) command" ) print ( "now the value held by Pi_num is:" ) Pi_num = round (Pi_num, 3 ) print (Pi_num) |