Write a python function to find and display the five digit number in which the first digit is two more than the second, the second digit is two more than the third, the fourth digit is two less than the third, and the last digit is two more than the fourth. The sum of the third, fourth, and fifth digits equals the first. The sum of all the digits is 19.
Answers
Answer:
Explanation:
Def find _five_digit():
For I in range (9,0,-1):
D1=i
D2=i-2
D3=i-4
D4=i-6
D5=i-4
If(d1==d3+d4+d5 and sum([d1,d2,d3,d4,d5])==19:
Num=0
For i in [d1,d2,d3,d4,d5]:
Num=num*10+i
Print(num)
Else:
Continue
Find_five_digits()
On writing a python function to find and display the five digit number based on the given condition, the output resulted is 75313.
Language Used : Python Programming
Program :
def fivedigitnumber():
#Let us keep i as a constant and then complete the relation of other terms
for i in range(9,0,-1):
first=i
second = i-2
third=i-4
fourth=i-6
fifth=i-4
#checking the condition
if third+fourth+fifth==first:
if (first+second+third+fourth+fifth)==19:
return(int(str(first)+str(second)+str(third)+str(fourth)+str(fifth)))
print(fivedigitnumber())
Output :
75313
Explanation :
- Keeping 'i' as constant variable and allocating it to the first number, we start to analyze the remaining numbers' relations.
- As it is given that first number is two more than the second, it means the second is 2 less to the first, i.e., second=i-2
- In similar format, we will solve the cryptic text into the allocating relations in 'i' to the corresponding numbers.
- Once we allocate the cryptic values in 'i' to each number, based on the condition given, we write if statements checking whether the relations meet the conditions third+fourth+fifth equals first and first+second+third+fourth+fifth equals 19
- If yes, we convert all the digits to strings, concatenate them in the same order and then make it into the integer using int() and then return the result. else; the loop runs on until it finds the result.
- If no result found, it results None.
Note : I have added the attachments of the interpretation and the execution of programs with their outputs. Take a look!
Quick Tip : In python, you must and should follow Indentation. Following the indentation property in any programming language will help you in quickly analysing the code, if an error occurs.
Learn a bit more about functions and methods to solve, here:
- Looking for some other methods to solve this type of questions? Here is the one.
https://brainly.in/question/14866549
- Calling a function in python.
https://brainly.in/question/11239798
Thank you for stopping by! Hope this answer helps you.