-1

Hodwy! I am writing a code for school in which you have to write a program that converts user input into pig Latin. My code was successful until I added a conditional statement that is required. My code is:

import sys
   while g < 10:  # Start an infinite loop
    
    message = input("Enter message or type stop: ")
    message = message.strip()
    
    if message == 'stop' or 'Stop':
        print('\nProgram terminated'), sys.exit()
    elif message != 'Stop' or 'stop':
        wordList = message.lower().split()
        vowels = ['a', 'e', 'i', 'o', 'u']
        Message_list = []
        eachWord = []
        for word in wordList:
            if word[0] in 'aeiou':  # case where vowel is first
                Message_list.append(word + 'yay')
            else:
                for letter in word:
                    if letter in 'aeiou':
                        Message_list.append(word[word.index(letter):] + word[:word.index(letter)] + 'ay')
                        break

I can not get proper indentation (with the while statement) on here, but in my code, the indentation is correct so that is not the problem. The code works perfectly if I remove:

 if message == 'stop' or 'Stop':
        print('\nProgram terminated'), sys.exit()

However, when I add it, the conditional always executes. I have no idea what the problem is because that is a valid conditional statement. Do any of you know what's going on?

Blh3339
  • 3
  • 2

1 Answers1

0

That is the equivalent of

if (message == 'stop') or 'Stop':

Working options include

if message == 'stop' or message == 'Stop':

if message in ('stop', 'Stop'):

if message.upper() == "STOP":
tdelaney
  • 73,364
  • 6
  • 83
  • 116