REALLY simple functions with tuples (python)
<p>I know this is really easy but I can't understand how to code at all. So I need to create two functions (if you can only help me with one that's fine):</p>

<p>Function a which receives a positive integer and transforms it into a tuple, like this:</p>

<pre><code>&gt;&gt;&gt;a(34500)
(3, 4, 5, 0, 0)
&gt;&gt;&gt;a(3.5)
ValueError: a: error
</code></pre>

<p>And function b which receives a tuple and transforms it into an integer, like this:</p>

<pre><code>&gt;&gt;&gt;b((3, 4, 0, 0, 4))
34004
&gt;&gt;&gt;b((2, âaâ, 5))
ValueError: b: error
</code></pre>

<p>I haven't learned much yet, only functions, while and for cycles, tuples, raise and isinstance(for the error message?), and probably some other things. I've tried looking for answers but they all used things I haven't learned.</p>

<pre><code>def to_tuple(input_number):
    # check if input number is int or not
    if isinstance(input_number,(int)):
        # convert number to string
        to_string = str(input_number)
        # finally convert string to
        # list of numbers followed by converting the list to tuple
        tuple_output = tuple(map(int,to_string))
        return tuple_output
    # if not int return empty tuple
    # well coz nobody likes useful but ugly python tracebacks
    else:
        return ()

# lets see example
number = 3450
print to_tuple(number)
(3, 4, 5, 0)

number = 353984
print to_tuple(number)
(3, 5, 3, 9, 8, 4)

number = 2.6
print to_tuple(number)
()
</code></pre>

<p>If you like this example I'd post answer for the second part</p>

python function tuples