- 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 number can be displayed using seven segment led in Python

Suppose we have a number n, and we have another input c. We have to check whether n can be displayed using 7-segment displays or not. Now here is a constraint. We are only allowed to glow at most c number of LEDs.

So, if the input is like n = 315 c = 17, then the output will be True as 315 needs 12 LEDs and we have 17.

To solve this, we will follow these steps −

- seg := a list containing led counts for all digits : [6, 2, 5, 5, 4, 5, 6, 3, 7, 6]
- s := n as string
- led_count := 0
- for i in range 0 to size of s - 1, do
- led_count := led_count + seg[value for ith character]

- if led_count <= c, then
- return True

- return False

## Example

Let us see the following implementation to get better understanding −

seg = [6, 2, 5, 5, 4, 5, 6, 3, 7, 6] def solve(n, c) : s = str(n) led_count = 0 for i in range(len(s)) : led_count += seg[ord(s[i]) - 48] if led_count <= c: return True return False n = 315 c = 17 print(solve(n, c))

## Input

315, 17

## Output

True

- Related Questions & Answers
- Check if mirror image of a number is same if displayed in seven segment displays in Python
- Maximum number that can be display on Seven Segment Display using N segments in C++
- Seven Segment Displays
- Interfacing 7(Seven) Segment Display to 8085 Microprocessor
- Check if a number can be expressed as a^b in Python
- Check if a number can be expressed as power in C++
- Check if a number can be expressed as a^b in C++
- Check if item can be measured using a scale and some weights in Python
- Check if a two-character string can be made using given words in Python
- How to check if an image is displayed on page using Selenium?
- Check if array can be sorted with one swap in Python
- Check if a prime number can be expressed as sum of two Prime Numbers in Python
- Check if the array can be sorted using swaps between given indices only in Python
- Check if a queue can be sorted into another queue using a stack in Python
- Check if a string can be formed from another string using given constraints in Python

Advertisements