Pick the simplest line of code to test if the word "BASIC" is stored in the variable text1.

if ( text1 == "BASIC" ):

if (text1 == BASIC ):

if (text1 == str("BASIC") ):

if ( int(text1) == BASIC ):

Answer :

The simplest line of code to test if the word "BASIC" is stored in the variable text1 is :

if ( text1 == "BASIC" ):

Explanation:

  • The simplest if-statement has two parts, a boolean "test" within parentheses ( ) followed by "body" block of statements within curly braces { }.
  • The test can be any expression that evaluates to a boolean value  true or false. The if-statement evaluates the test and then runs the body code only if the test is true.
  • You should use the equals() method of the String class to compare Strings.
  • == will do an object comparison between the strings in this situation, and although the value may be the same of the String objects, the objects are not the same.
  • Equals: a == b. The double equals sign =. A single symbol a = b would mean an assignment

Answer:

if (text1 == str("BASIC") ):

Explanation: yes

Other Questions