logo CodeStepByStep logo

first_digit

Language/Type: Python loops %

Write a function named first_digit that returns the first digit of an integer. For example, first_digit(3572) should return 3. It should work for negative numbers as well. For example, first_digit(-947) should return 9.

Call Value Returned
first_digit(3572) 3
first_digit(-947) 9
first_digit(6) 6
first_digit(35) 3
first_digit(123456) 1

Do not use a string to solve this problem.

Function: Write a Python function as described, not a complete program.

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.