

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Check if mirror image of a number is same if displayed in seven segment displays in Python
Suppose we have a number n. We have to check whether the mirror image of the number is same as the given number or not when it is displayed on Seven Segment display.
So, if the input is like n = 818, then the output will be True.
the mirror image is same.
To solve this, we will follow these steps −
- num_str := n as string
- for i in range 0 to size of num_str - 1, do
- if num_str[i] is not nay of ['0', '1', '8'] then, then
- return False
- if num_str[i] is not nay of ['0', '1', '8'] then, then
- left := 0
- right := size of num_str - 1
- while left < right, do
- if num_str[left] is not same as num_str[right], then
- return False
- left := left + 1
- right := right - 1
- if num_str[left] is not same as num_str[right], then
- return True
Example
Let us see the following implementation to get better understanding −
def solve(n): num_str = str(n) for i in range(len(num_str)): if num_str[i] not in ['0', '1', '8']: return False left = 0 right = len(num_str) - 1 while left < right: if num_str[left] != num_str[right]: return False left += 1 right -= 1 return True n = 818 print(solve(n))
Input
818
Output
True
- Related Questions & Answers
- Check if number can be displayed using seven segment led in Python
- Seven Segment Displays
- How to check if an image is displayed on page using Selenium?
- Check if the frequency of all the digits in a number is same in Python
- Check if a key is present in every segment of size k in an array in Python
- Check if binary representation of a number is palindrome in Python
- Check if a number is a Trojan Numbers in Python
- Check if leaf traversal of two Binary Trees is same in Python
- Check if a number has same number of set and unset bits in C++
- Python Program to Check if a Number is a Perfect Number
- Python Program to Check if a Number is a Strong Number
- Check if a given string is a valid number in Python
- Python - Check if all elements in a List are same
- Check if a number is Palindrome in C++
- Check if a number is Bleak in C++
Advertisements