dimanche 21 novembre 2021

How do i return Number to text in python?

I am struggeling with following:

"I am going to write a function - single parameter - which can be a number from 1 to 10. depending on this parameter, it should return the text of the number entered. if the parameter is 1, the function should set the text "one", if the parameter is two it should return "two" and so on."

How do I get this to become a for loop?

def numberToText(input): 
   if input == 1:
      return "one"
   if input == 2: 
      return "two"
return input

print(numberToText(input))

Aucun commentaire:

Enregistrer un commentaire