CBSE Class 11 Computer Science
Question 30 of 43
Flow of Control — Question 18
Back to all questions 18
Question Question 18
Write a complete Python program to do the following :
(i) read an integer X.
(ii) determine the number of digits n in X.
(iii) form an integer Y that has the number of digits n at ten's place and the most significant digit of X at one's place.
(iv) Output Y.
(For example, if X is equal to 2134, then Y should be 42 as there are 4 digits and the most significant number is 2).
Solution
x = int(input("Enter an integer: "))
temp = x
count = 0
digit = -1
while temp != 0 :
digit = temp % 10
count += 1
temp = temp // 10
y = count * 10 + digit
print("Y =", y)Output
Enter an integer: 2134
Y = 42
x
=
int
(
input
(
"Enter an integer: "
))
temp
=
x
count
=
0
digit
=
-
1
while
temp
!=
0
:
digit
=
temp
%
10
count
+=
1
temp
=
temp
//
10
y
=
count
*
10
+
digit
print
(
"Y ="
,
y
)
Output
Enter an integer: 2134
Y = 42