in Education by
I have two integer values a and b, but I need their ratio in floating point. I know that a < b, and I want to calculate a / b, so if I use integer division I'll always get 0 with a remainder of a. How can I force c to be a floating point number in Python in the following? c= a / b Select the correct answer from above options

1 Answer

0 votes
by
 
Best answer
Python 3 gives us the feature that we can directly get the value as a floating point by using division (/) operator. For getting the value in a floating point you can import a library called __future__. from __future__ import division a = 4 b = 6 c= a / b C Here is the way by which you can get your desired output. Another thing you can do is type-cast the b value into a float. That will also give you float value as output.

Related questions

0 votes
    How can someone parse a numeric string like "121.5555" to it's corresponding float value 121.5555? or parse a ... str to an int. Select the correct answer from above options...
asked Jan 21, 2022 in Education by JackTerrance
0 votes
    Is there a way to step between 0 and 1 by 0.1? I thought I could do it like the following, but it failed: ... , which I did not expect. Select the correct answer from above options...
asked Jan 30, 2022 in Education by JackTerrance
0 votes
    Can anyone tell me how I can represent the equivalent of an Enum in Python? Select the correct answer from above options...
asked Jan 22, 2022 in Education by JackTerrance
0 votes
    When you just want to do a try-except without handling the exception, how do you do it in Python? Is the ... rmtree(path) except: pass Select the correct answer from above options...
asked Jan 26, 2022 in Education by JackTerrance
0 votes
    Can anyone please explain, what is setup.py and how can it be configured or used? Select the correct answer from above options...
asked Feb 2, 2022 in Education by JackTerrance
0 votes
    >>> a=[1,2,3] >>> a.remove(2) >>> a [1, 3] >>> a=[1,2,3] >>> del a[1] >>> a ... above three methods to remove an element from a list? Select the correct answer from above options...
asked Jan 26, 2022 in Education by JackTerrance
0 votes
    Can someone tell me a python -m SimpleHTTPServer equivalent Python 3? Select the correct answer from above options...
asked Jan 23, 2022 in Education by JackTerrance
0 votes
    A categorical variable V1 in a data frame D1 can have values represented by the letters from A to Z. I want to create a ... B','N',T')) Select the correct answer from above options...
asked Feb 8, 2022 in Education by JackTerrance
0 votes
    According to the R language definition, the difference between & and && (correspondingly | and ||) is that the former ... OrElse in R? Select the correct answer from above options...
asked Feb 8, 2022 in Education by JackTerrance
0 votes
    Can someone state the difference between the assignment operators = and...
asked Jan 20, 2022 in Education by JackTerrance
0 votes
    I'm trying to do the Udacity mini project and I've got the latest version of the SKLearn library ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 24, 2022 in Education by JackTerrance
0 votes
    I used the function for gower distance from this link: https://sourceforge.net/projects/gower-distance- ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    I have two Dataframes : DF1(That i've just resampled): Mi_pollution.head(): Sensor_ID Time_Instant ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 3, 2022 in Education by JackTerrance
0 votes
    I'm creating my first program on python. The objective is to get an output of trip cost. In the ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 21, 2022 in Education by JackTerrance
0 votes
    Hi Everyone I'm Having This Two Columns: Mi_Meteo['Measurement'] = Mi_Meteo['Measurement'].str.rstrip(' ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 20, 2022 in Education by JackTerrance
...