-4

I have created the code below to capitalize and lower case of the inputted text. The upper-casing works. Lowercasing doesn't work the first time it is inputted, until this is actives.

if (Qtext != "Upper" and "Lower"):

    print("Please use valid word.")
    Qtext = input("Write Upper for text to be Uppercased and Lower for text to be Lower Cased: ")

and only works on the second try. Please tell me how to fix it and why this is happening.

Full code below.

def L(Text1):
  return Text1.lower()

def U(Text2):
  return Text2.upper()

  
for X in range(10):
  Etext = input("Enter a text: ")
  Qtext = input("Write Upper for text to be Uppercased and Lower for text to be Lower Cased: ")
  
  if (Qtext != "Upper" and "Lower"):
    
    print("Please use valid word.")
    Qtext = input("Write Upper for text to be Uppercased and Lower for text to be Lower Cased: ")
    
  if (Qtext == "Upper"):
    print(U(Etext))
  if (Qtext == "Lower"):
    print(L(Etext))
jonrsharpe
  • 107,083
  • 22
  • 201
  • 376
Newbee
  • 1
  • 3
    The code `if (Qtext != "Upper" and "Lower")` doesn't do what you want in *any* programming language afaik. Use: `if Qtext not in ["Upper", "Lower"]`. Also, no need for the parentheses. Also, if you want to keep re-prompting the user until you get a valid input then make this a `while` loop. – jarmod May 22 '22 at 15:48
  • Thanks for the answer. Work wonderfully! This will be a great help from now on, "if not in [a,b]" And I will get started to learn the While loops now. – Newbee May 22 '22 at 15:58

0 Answers0