TypeError remains: Str object is not callable
<p>I'm trying to make a python program that converts a 24-hour notation to a 12-hour notation, but the linux shell keeps saying: 'Str' object is not callable.
I'm looking for hours now but can't find the solution?
Do you people see it?</p>

<p>def time(time, hours, minutes):</p>

<pre><code>    """ Changes time from 24-hour notation to 12-hour notation and adds postfix"""
    if int(hours) &gt; 12:
        x = ("{0:&lt;20}, is the same time as{1:&gt;20}{2:&gt;20}".format(time, hours -12 + ":" + minutes, "PM"))
        return x
    if int(hours) &lt; 12 and int(minutes) != 00 :
        x = ("{0:&lt;20}, is the same time as{1:&gt;20}{2:&gt;20}".format(time, time, "AM"))
        return x
    if int(hours) == 00 and int(minutes) == 00:
        x = ("{0:&lt;20}, is the same time as{1:&gt;20}{2:&gt;20}".format(time, hours +12 + ":" + minutes, "AM")) 
        return x
    if int(hours) == 12 and int(minutes) == 00:
        x = ("{0:&lt;20}, is the same time as{1:&gt;20}{2:&gt;20}".format(time, time , "PM"))
        return x
</code></pre>

<p>def main():</p>

<pre><code>    print("{0:^30}".format("24h times converted to 12h times"))
    for time in sys.stdin:
        hours, minutes = time.split(':')
        y = time(time,hours, minutes)
        print (y)
</code></pre>

<p>if <strong>name</strong> == "<strong>main</strong>":
        main()</p>

<p>In the main loop you are using same name for the Function and the String i.e "time".
This is causing ambiguity. Give them a different name and it will work fine.
Use Like this.</p>

<pre><code>for timeString in sys.stdin:
        hours, minutes = timeString.split(':')
        y = time(timeString,hours, minutes)
        print (y)
</code></pre>

<p>Hope this helps.</p>

python string object typeerror