How to efficiently implement a 7-segment display?

I want to construct a 7 segment display (as shown below). When you input a number, the script will read the input number and light up the respective segment
(change the spriterenderer color to red) to display the number.

But I think the code has become too long, since there is 0-9 digit to display, I need 10 if statements, 8 scripts and the function of each statement is to light up the respective segment so it displays the number correctly.

Is there any better way to make the code shorter?

using UnityEngine;

public class ClockController :  MonoBehaviour
{
    Rect1 rect1;
    Rect2 rect2;
    Rect3 rect3;
    public GameObject othergameobjectrect2;
    public GameObject othergameobjectrect3;

    void Start()
    {
        int x = 1;
        if (x == 1)
        {
            rect1 = GetComponent<Rect1>();
            rect1.Rectangle1();
           
            rect2 = othergameobjectrect2.GetComponent<Rect2>();
            rect2.Rectangle2();

            rect3 = othergameobjectrect3.GetComponent<Rect3>();
            rect3.Rectangle3();

        }
    }
}
using UnityEngine;

public class Rect3 : MonoBehaviour
{
    public void Rectangle3()
    {
        GetComponent<SpriteRenderer>().color = Color.red;
        
    }
}
using UnityEngine;

public class Rect2 : MonoBehaviour
{
    public void Rectangle2()
    {
         GetComponent<SpriteRenderer>().color = Color.red; 
    }
}
using UnityEngine;

public class Rect1 : MonoBehaviour
{   
    public void Rectangle1()
    {    
        GetComponent<SpriteRenderer>().color = Color.red;    
    }
}

enter image description here

python – Python3 printing on the same line – Numbers in 7-segment device format

I am new to Python and am having trouble printing the output on one line.

This relates to the Python Learning Python Essentials Lab 5.1.10.6 online class and printing to a 7-segment device. If you're not familiar with a 7-segment device, check out Wikipedia.

I do not use any external device. I only need it to print on my own terminal. All the other StackOverflow solutions that I have found are related to the use of real devices and have not helped.

  • Laboratory link:
    https://edube.org/learn/programming-essentials-in-python-part-2/lab-a-led-display

  • Purpose: To request a number from the user; print number on 7-segment display
    format to your terminal.

  • Notes: Usage Python 3.9. I have tried 3 alternative solutions (Option 1,2,3), but none do what I want.
  • INSTRUCTIONS: One / How Option 1, 2 or 3 to execute only this option
  • I found this alternative solution, which I mainly understand and which achieves what I am trying to accomplish. However, this is a totally different approach and not the one I would have imagined. I know there are many ways to dress up a 7-segment device, and if that is the most correct, then I will learn it. But I feel like I'm so close and only superfluous 'n' far from finding out with my own method and i'm just trying to figure out what i'm missing.

Thank you for your help.

Desired output

###   ##  ###  ###  # #  ###  ###  ###  ###  ###  
# #  ###    #    #  # #  #    #      #  # #  # #  
# #   ##  ###  ###  ###  ###  ###    #  ###  ###  
# #   ##  #      #    #    #  # #    #  # #    #  
###   ##  ###  ###    #  ###  ###    #  ###  ###

My code

# clear screen each time you run the script
import os
clear = lambda: os.system('cls')
clear()
# 
# Dictionary of (number:7-segment-hash)
dict1 = {
    '0':('###','# #','# #','# #','###'),
    '1':('#####'),
    '2':('###',"https://serverfault.com/#",'###',"https://serverfault.com/#",'###'),
    '3':('###',"https://serverfault.com/#",'###',"https://serverfault.com/#",'###'),
    '4':('# #','# #','###',"https://serverfault.com/#","https://serverfault.com/#"),
    '5':('###',"https://serverfault.com/#",'###',"https://serverfault.com/#",'###'),
    '6':('###',"https://serverfault.com/#",'###','# #','###'),
    '7':('###',"https://serverfault.com/#","https://serverfault.com/#","https://serverfault.com/#","https://serverfault.com/#"),
    '8':('###','# #','###','# #','###'),
    '9':('###','# #','###',"https://serverfault.com/#",'###')
}

# Function to print numbers in 7-segment-device format
def fun_PrintNums(num):
    if num < 0 or num % 1 > 0 or type(num)!=int:    # if num is NOT a positive whole integer
        return "Invalid entry, please try again"
    else: 
        display = ''
        for i in str(num):      # convert 'num' to STRING; for each "number" in string 'num"https://serverfault.com/#"''Option 1: works, but prints nums vertically instead of side-by-side; Return=None ''' #
            for char in dict1(i):
                print(*char)
print(fun_PrintNums(int(input("Enter any string of whole numbers: "))))
#----------------------------------------------------------------#


#''' Option 2: Return works, but still vertical and not spaced out ''' #
#             for char in dict1(i):
#                 display.append(char)
#     return display
# print('n'.join(fun_PrintNums(int(input("Enter any string of whole numbers: ")))))
#---------------------------------------------------------------------#

#''' Option 3: 'display' row1 offset; spaced out as desired, but vertical; Return=None''' #
#             for char in dict1(i):                
#                 display += char
#                 display += 'n'
#     a = print(*display,end='')
#     return a
# print(fun_PrintNums(int(input("Enter any string of whole numbers: "))))
#---------------------------------------------------------------#

Option 1 Exit
Works, but prints nums vertically instead of side by side; Return = None

# # #
    #
# # #
#    
# # #
# # #
    #
# # #
    #
# # #
None 

Option 2 Exit
Return works, but always vertical and not spaced


###
  #
###
#  
###
###
  #
###
  #
###

Option 3 Exit
& # 39; display & # 39; offset row1; spaced as desired, but vertical; Return = None

  # # # 
     #  
 # # #  
 #      
 # # #  
 # # #  
     #  
 # # #  
     #  
 # # #  
None  

Computer architecture – Addition of two 4-bit binary numbers in 2 7-segment LEDs up to 30

Thank you for providing an answer to Computer Science Stack Exchange!

  • Make sure you respond to the question. Give details and share your research!

But to avoid

  • Ask for help, clarification, or answer other answers.
  • Make statements based on the opinion; back them up with references or personal experience.

Use MathJax to format the equations. MathJax reference.

To learn more, read our tips on writing good answers.