Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
help
#1
import time

digit_patterns = {
    0: [[1, 1, 1],  [1, 0, 1], [1, 0, 1], [1, 0, 1], [1, 1, 1]],
    1: [[1, 0, 0],  [1, 0, 0], [1, 0, 0], [1, 0, 0], [1, 0, 0]],
    2: [[1, 1, 1],  [0, 0, 1], [1, 1, 1], [1, 0, 0], [1, 1, 1]],
    3: [[1, 1, 1],  [0, 0, 1], [1, 1, 1], [0, 0, 1], [1, 1, 1]],
    4: [[1, 0, 1],  [1, 0, 1], [1, 1, 1], [0, 0, 1], [0, 0, 1]],
    5: [[1, 1, 1],  [1, 0, 0], [1, 1, 1], [0, 0, 1], [1, 1, 1]],
    6: [[1, 1, 1],  [1, 0, 0], [1, 1, 1], [1, 0, 1], [1, 1, 1]],
    7: [[1, 1, 1],  [0, 0, 1], [0, 0, 1], [0, 0, 1], [0, 0, 1]],
    8: [[1, 1, 1],  [1, 0, 1], [1, 1, 1], [1, 0, 1], [1, 1, 1]],
    9: [[1, 1, 1],  [1, 0, 1], [1, 1, 1], [0, 0, 1], [1, 1, 1]]
}
def display_digit(digit):
    led_pattern = digit_patterns[digit]
    for row in led_pattern:
        print(end = "    ")
        for led in row:
            if led:
                print("#", end="")
            else:
                print(" ", end="")
        print()

# Function to simulate the seven-display device
def simulate_seven_display(number):
    digits = [int(digit) for digit in str(number)]
    for digit in digits:
        display_digit(digit)
        time.sleep(1.5)  # Adjust delay as needed
        print()
# Example usage
number_to_display = input("enter a number: ")
simulate_seven_display(number_to_display)
I want this code to display the digits of the input number next to each others horizontally in the same line not under each other
Larz60+ write Aug-26-2024, 08:36 AM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.

Attached Files

Thumbnail(s)
   
Reply
#2
import time

digit_patterns = {
    0: [[1, 1, 1],  [1, 0, 1], [1, 0, 1], [1, 0, 1], [1, 1, 1]],
    1: [[1, 0, 0],  [1, 0, 0], [1, 0, 0], [1, 0, 0], [1, 0, 0]],
    2: [[1, 1, 1],  [0, 0, 1], [1, 1, 1], [1, 0, 0], [1, 1, 1]],
    3: [[1, 1, 1],  [0, 0, 1], [1, 1, 1], [0, 0, 1], [1, 1, 1]],
    4: [[1, 0, 1],  [1, 0, 1], [1, 1, 1], [0, 0, 1], [0, 0, 1]],
    5: [[1, 1, 1],  [1, 0, 0], [1, 1, 1], [0, 0, 1], [1, 1, 1]],
    6: [[1, 1, 1],  [1, 0, 0], [1, 1, 1], [1, 0, 1], [1, 1, 1]],
    7: [[1, 1, 1],  [0, 0, 1], [0, 0, 1], [0, 0, 1], [0, 0, 1]],
    8: [[1, 1, 1],  [1, 0, 1], [1, 1, 1], [1, 0, 1], [1, 1, 1]],
    9: [[1, 1, 1],  [1, 0, 1], [1, 1, 1], [0, 0, 1], [1, 1, 1]]
}
def display_digit(digit):
    led_pattern = digit_patterns[digit]
    for row in led_pattern:
        print(end = "    ")
        for led in row:
            if led:
                print("#", end="")
            else:
                print(" ", end="")
        print()

# Function to simulate the seven-display device
def simulate_seven_display(number):
    digits = [int(digit) for digit in str(number)]
    for digit in digits:
        display_digit(digit)
        time.sleep(1.5)  # Adjust delay as needed
        print()

# Example usage
number_to_display = input("enter a number: ")
simulate_seven_display(number_to_display)
[input]
enter a number: 123
[/input]

Output:
# # # # # ### # ### # ### ### # ### # ###
Quote:my code doesn't not give any error I want to know how to modify it so the numbers printed horizontally not vertically
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020