[Python] Trying to convert int to string without using in-built function in python 3

Discussão em 'Python' iniciado por Stack, Dezembro 18, 2024.

  1. Stack

    Stack Membro Participativo

    def int_to_str(num):
    is_negative = False
    if num:
    num, is_negative = -num, True
    s = []
    while True:
    s.append(chr(ord('0') + num % 10))
    num //= 10
    if num == 0:
    break
    return ('-' if is_negative else '') + ''.join(reversed(s))
    num = input("Enter any numeric value: ")
    print(int_to_str(num))

    Continue reading...

Compartilhe esta Página