Accept a three digit number such that the difference between the first and last digit is 2.If not then print a message "Wrong Input" .
Answers
Answered by
1
a=int(input('enter any three digit no. '))
b=int(a/100)%10 # First digit
print(b)
c=a%10 # Last digit
print(c)
if (c-b) == 2:
print('correct input')
else:
print('wrong input')
Dry run
enter any three digit no. 456
4
6
correct input
explanation
'a' will take input (like 456)
in 'b' 456/100 = 4.56 then int(4.56) = 4 then 4%10 = 4
in 'c' 456%10 = 6
c-b = 2
if (c-b) == 2 #true
correct input
Similar questions
Science,
3 months ago
Psychology,
3 months ago
Computer Science,
3 months ago
Political Science,
7 months ago
History,
7 months ago
History,
11 months ago
Science,
11 months ago
Science,
11 months ago