Ad
Fundamentals

shorter

Code
Diff
  • def main():
        word = input('Enter a string\n> ')
        print(f'>> The output is:  {word.upper()}')
    
        while True:
            play_again = input('Would you like to play (y)es or (n)o :\n> ')
    
            if play_again == 'y':
                return main()
    
            elif play_again == 'n':
                print('goodbye')
                break
                
            else:
                print('Incorrect input!')
                continue
    
    
    if __name__ == '__main__':
        main()
    • import sys
    • def main():
    • while True:
    • word = input('Enter a string
    • > ')
    • print(f'>> The output is: {word[::-1].upper()}')
    • word = input('Enter a string
    • > ')
    • print(f'>> The output is: {word.upper()}')
    • while True:
    • play_again = input('Would you like to play (y)es or (n)o :
    • > ')
    • while True:
    • play_again = input('Would you like to play (y)es or (n)o :
    • > ')
    • if play_again == 'y':
    • return main()
    • if play_again == 'y':
    • return main()
    • elif play_again == 'n':
    • print('goodbye')
    • sys.exit()
    • else:
    • print('Incorrect input!')
    • continue
    • elif play_again == 'n':
    • print('goodbye')
    • break
    • else:
    • print('Incorrect input!')
    • continue
    • if __name__ == '__main__':
    • main()