Decode School

Decode School - The School for Problem Solvers
Welcome to My Blog.
Need Assignment / Project Guidance (or) Training in Python?

Print the first Digit of a Number using Python

Get a number and print its First Digit.

Sample Input 1:

Enter the number: 234

Sample Output 1:

2 is the first digit of 234

Program or Solution

					    
							

num = int(input("enter a number"))

n = num

while n > 10:

    n = n // 10

print("{} is the first digit of {}".format(n,num))

Program Explanation

divide the number by 10 till number is greater than 10, once it is less than 10 then print the number. you will get the first digit.