Posts: 2
Threads: 1
Joined: Aug 2024
Aug-25-2024, 11:34 PM
(This post was last modified: Aug-27-2024, 09:30 AM by Larz60+.)
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)
Posts: 2
Threads: 1
Joined: Aug 2024
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
|