Header Ads Widget

Write a Python program to receive a five-digit no and display as like 24689: 2 4 6 8 9

 

 Write  a Python program to receive a five-digit no and display as like 24689: 2 4 6 8 9

Given a five digit number , write a  program to receive a five-digit no and display as like 24689: 2 4 6 8 9 .

Sample input

24986

Sample output

6 8 9 4 2

 Write  a Python program to receive a five-digit no and display as like 24689: 2 4 6 8 9

The objective of the code is to print the digits of the number by space separated .

Algorithm:

  1. Take input a 5-digit number from the user.
  2. Convert the number to string format using str() function.
  3. Iterate through each character of the string using a for loop.
  4. Print each character separated by a space.

Code(Python):-

num = input("Enter a five-digit number: ")
print(num + ":", end=" ")

for digit in num:
print(digit, end=" ")


Output:

Enter a five-digit number: 24986:
6 8 9 4 2

Explanation:

  1. The program starts by taking input from the user using the input() function and storing it in the variable num.
  2. The program then prints the input number along with a colon using the print() function. The end parameter is used to avoid printing a newline character.
  3. The program then iterates through each character of the input number using a for loop.
  4. During each iteration of the loop, the program prints the current character of the number followed by a space, using the print() function with the end parameter set to a space.

Recommended Post :-

HCL Coding Questions:-

Capgemini Coding Questions:-

Companies interview:-

Full C course:-    

Key points:-

Cracking the coding interview:-

 Array and string:-

Tree and graph:-

Hackerearth Problems:-

Hackerrank Problems:-

Data structure:-

 MCQs:-