
- Python 3 Basic Tutorial
- Python 3 - Home
- What is New in Python 3
- Python 3 - Overview
- Python 3 - Environment Setup
- Python 3 - Basic Syntax
- Python 3 - Variable Types
- Python 3 - Basic Operators
- Python 3 - Decision Making
- Python 3 - Loops
- Python 3 - Numbers
- Python 3 - Strings
- Python 3 - Lists
- Python 3 - Tuples
- Python 3 - Dictionary
- Python 3 - Date & Time
- Python 3 - Functions
- Python 3 - Modules
- Python 3 - Files I/O
- Python 3 - Exceptions
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 Articles
- Check if number can be displayed using seven segment led in Python
- Seven Segment LED 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
- If we stand in front of a plane mirror why our image is not the same as the real image?
- Check if binary representation of a number is palindrome in Python
- Check if a number is a Trojan Numbers in Python
- Check if a key is present in every segment of size k in an array 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 - Check if all elements in a List are same
- Check if a number is an Achilles number or not in Python
- Check if a given string is a valid number in Python
- Check if given number is perfect square in Python
- Check if a number is Primorial Prime or not in Python

Advertisements