Computer Science, asked by loganihrishi, 2 months ago

Write a python program to input a number n and Write a menu driven program to
do the following:

(i) Count all even digits of the number n
(ii)form a number by incrementing each digit by 1. The digit 9 should
be replaced with 0.
For example: if the orignal number is 129, the new number should be 230. ​

Answers

Answered by madhalaimuthucharlas
0

Answer:

a = str(input("ENTER: "))

L = []

for i in a:

num = int(i)

num += 1

if num > 9:

num = 0

L.append(num)

else:

L.append(num)

print (int(''.join(str(i) for i in L)))

Answered by anindyaadhikari13
0

Answer:

This is the required program for the question in Python 3.

num=int(input("Enter the number: "))

print("\n1. Count Even Digits.")

print("2. Modify the number.")

n=int(input("\nEnter your choice: "))

if n==1:

c=[int(letter)%2 for letter in str(num)].count(0)

print("Number of even digits: ",c)

elif n==2:

m=0

for letter in str(num):

x=int(letter)+1

if x==10:

x=0

m=m*10+x

print("Number after modifications:",m)

else:

print("Invalid Choice.")

Explanation:

  • The above question is solved using if-else. We are asked to enter a number from the user and according to his/her choice, we have to perform the operation.

  • To do this, we will ask the user to enter the number at first. Then, we will display the conditions which is given. Now, we will ask the user to enter the choice.

  • If the choice is 1, we will count the number of even digits. To do this, we will store the remainder obtained when each digit of the number is divided by 2 in a list. We can either get result as 0 or 1. Then, we will count the number of zeros present in the list. The result is equal to the number of even digits present in the number. Time to display the result.

  • If the choice is 2, we will first declare a variable m = 0 and then simply convert the number to string, access all the letters of the string, convert them to number and add 1 to it. If the result is 10, we will change the result from 10 to 0. Then, we will multiply m by 10 and add the result to it. Result obtained is the modified number.

  • If the choice is other than 1 or 2, an error message will be displayed.

See the attachment for output ☑.

Attachments:
Similar questions