12/20/2020

Python Explanation(Edabit // Drunken Python)

 Hello!

Today's question is this!

Python got drunk and the built-in functions str() and int() are acting odd:

str(4) ➞ 4

str("4") ➞ 4

int("4") ➞ "4"

int(4) ➞ "4"

You need to create two functions to substitute str() and int(). A function called int_to_str() that converts integers into strings and a function called str_to_int()that converts strings into integers.


And this is my solved code!

str, int = int, str


def int_to_str(n):
return str(n)


def str_to_int(s):
return int(s)

 

 First, we make two function int_to_str and str_to_int.

Inside int_to_str we return the number stringed.

Inside str_to_int we return the string numbered.


Easy!!!


Bye!!!!!!!



0 件のコメント:

Super Leo 4!

  Leo : Let's do this! Reimu : I'll kill those monsters, so you go! Leo : Yeah! I'll go to the goal!  Leo : Let's go〜! ? Wai...