Getting the ratio of a in b
<p>This is the current code I have, the issue is clearly that I can't divide strings by strings, but I'm unsure of how to go about editing the code to get it to run.</p>

<pre><code>def Fraction(c, s):
    #Returns the fraction of 's' formed by 'c'.
    return c / s
print(Fraction("a", "ababab"))
</code></pre>

<p>In theory, 0.5 should be printed; <code>'a'</code> forms half of all text in <code>'ababab'</code>.</p>

<p>Apparently you want a ratio here; a number between 0.0 and 1.0 indicating what percentage of a larger string is using a smaller string:</p>

<pre><code>def ratio(c, s):
    return (float(s.count(c) * len(c))) / len(s)
</code></pre>

<p>Demo:</p>

<pre><code>&gt;&gt;&gt; def ratio(c, s):
...     return (float(s.count(c) * len(c))) / len(s)
...
&gt;&gt;&gt; ratio("a", "ababab")
0.5
&gt;&gt;&gt; ratio("ab", "ababab")
1.0
</code></pre>

python python-3.x