10/25/2020

Python Explatnation (Edabit //Oddish and Evenish)

 Hello!

Today is going to be the python explanation!

Today's question is this!

Create a function that determines whether a number is Oddish or Evenish. A number is Oddish if the sum of all of its digits is odd, and a number is Evenish if the sum of all of its digits is even. If a number is Oddish, return "Oddish". Otherwise, return "Evenish".

For example, oddish_or_evenish(121) should return "Evenish", since 1 + 2 + 1 = 4. oddish_or_evenish(41) should return "Oddish", since 4 + 1 = 5.

Examples

oddish_or_evenish(43) ➞ "Oddish"

oddish_or_evenish(373) ➞ "Oddish"

oddish_or_evenish(4433) ➞ "Evenish


From : Oddish vs. Evenish


And my code is here!

def oddish_or_evenish(num):
strlist = list(str(num))
lst = []
for i in strlist:
lst.append(int(i))
num = sum(lst)
if num % 2 == 0:
return "Evenish"
else:
return "Oddish"

Let's see the code.

First, we make a list with string numbers.

It should be like this.

EG.

["4", "2", "1" ]

Next, we loop the string list and append the number to an empty list with integers.

Next, we sum(Plus) the list with integers.

It should be, 7. (From the example)

Lastly, we check if it is Evenish or Oddish, with checking with Modulo(%).

We mod with 2, and if it is 0, It is Evenish.

Otherwise, it is Oddish.

easy code, Right?

this is the algorithm.















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...