211k views
2 votes
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 ):

User Hala
by
3.9k points

2 Answers

6 votes

Answer:

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

Explanation: yes

User Dorjee
by
4.7k points
4 votes

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

if ( text1 == "BASIC" ):

Step-by-step 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
User Tdgtyugdyugdrugdr
by
3.7k points