You've surely seen a seven-segment display.
It's a device (sometimes electronic, sometimes mechanical) designed to present one decimal digit using a subset of seven segments. If you still don't know what it is, refer to the following Wikipedia article.
Your task is to write a program which is able to simulate the work of a seven-display device, although you're going to use single LEDs instead of segments.
Each digit is constructed from 13 LEDs (some lit, some dark, of course) - that's how we imagine it:
Note: the number 8 shows all the LED lights on.
Your code has to display any non-negative integer number entered by the user.
Tip: using a list containing patterns of all ten digits may be very helpful.
Sample input:
9081726354
Sample output:
An anagram[相同字母异序词]is a new word formed by rearranging the letters of a word, using all the original letters exactly once. For example, the phrases "rail safety" and "fairy tales" are anagrams, while "I am" and "You are" are not.
Your task is to write a program which:
Note:
Test your code using the data we've provided.
Sample input:
Listen
Silent
Sample output:
Anagrams
Sample input:
modern
norman
Sample output:
Not anagrams
1.# 相同字母异序词
# 相同字母异序词
def Anagram(s1, s2):
s1, s2 = s1.lower(), s2.lower()
lsts1 = list(s1)
lsts2 = list(s2)
lsts1.sort()
lsts2.sort()
for i, char in enumerate(lsts1):
if lsts2[i] != char:
return False
return True
def ab(s):
if s is False:
print("Not anagrams")
else:
print("Anagrams")
def main():
i="no"
while(i=="no"):
atest=input("请输入文本1:")
btest=input("请输入文本2:")
ab(Anagram(atest, btest))
i=input("是否退出程序 'yes/no': ")
main()
2.模拟led显示
#编写一个能够模拟七个显示设备的工作的程序,每个数字都是由13个led构成的
class NumFactory():
def __init__(self, n):
if n == '0':
self.list = ['# # #',
'# #',
'# #',
'# #',
'# # #']
elif n == '1':
self.list = [' #',
' #',
' #',
' #',
' #']
elif n == '2':
self.list = ['# # #',
' #',
'# # #',
'# ',
'# # #']
elif n == '3':
self.list = ['# # #',
' #',
'# # #',
' #',
'# # #']
elif n == '4':
self.list = ['# #',
'# #',
'# # #',
' #',
' #']
elif n == '5':
self.list = ['# # #',
'# ',
'# # #',
' #',
'# # #']
elif n == '6':
self.list = ['# # #',
'# ',
'# # #',
'# #',
'# # #']
elif n == '7':
self.list = ['# # #',
' #',
' #',
' #',
' #']
elif n == '8':
self.list = ['# # #',
'# #',
'# # #',
'# #',
'# # #']
elif n == '9':
self.list = ['# # #',
'# #',
'# # #',
' #',
'# # #']
while True:
num = input('请输入非负整数: ')
lenth = len(num)
for i in range(5):
for j in range(lenth):
print(NumFactory(num[j]).list[i], end=' ')
print()
break