I'm a noob to python and I wanted to make a "digital signboard". I only have "A" and "B" right now. I don't know how to exit out of the program completely using sys.exit(). I guess it only exits out of the function and then continues on to the next line of code to ask for the next letter. I want it to exit the program entirely once "end" is inputted but still have the letters displayed before it exits.
import time, sys
def getLetter(letter):
while True:
if letter =='A'or letter=='a':
print('<A>')
return
break
elif letter =='B'or letter=='b':
print('<B>')
return
break
elif letter == 'space':
print('')
time.sleep(0.1)
print('')
time.sleep(0.1)
print('')
time.sleep(0.1)
print('')
time.sleep(0.1)
print('')
time.sleep(0.1)
print('')
time.sleep(0.1)
print('')
time.sleep(0.1)
elif letter == 'end':
sys.exit('Signboard Terminated')
#instructions
print('Welcome to virtual signboard\n')
time.sleep(0.5)
print('Instructions:')
time.sleep(0.5)
print('Enter each character individually (max: 10 characters).')
time.sleep(0.5)
print('To enter a space, type "space"')
time.sleep(0.5)
print('To finish, type "end"')
print('Enter first character:')
firstLetter=input()
time.sleep(0.2)
print('\nEnter second character:')
secondLetter=input()
time.sleep(0.2)
print('\nEnter third character:')
thirdLetter=input()
time.sleep(0.2)
#getting output
output=getLetter(firstLetter)
output=getLetter(secondLetter)
output=getLetter(thirdLetter)
So ideally this would happen: Enter first character: A
Enter second character: end
and the whole program would stop there without asking for the second and third character but display A only
Aucun commentaire:
Enregistrer un commentaire