Respuesta :

Answer:

Here is the expression:

user_grade = 10 #assigns 10 to the value of user_grade

if user_grade >=9 and user_grade <=12:  #checks if the user_grade is between 9 and 12 inclusive

   print('in high school')  # prints in high school if above condition is true

else:  #if user_grade is not between 9 and 12 inclusive

   print('not in high school') # prints not in high school if user_grade is not between 9 and 12 inclusive

This can also be written as:

user_grade = 10  # assigns 10 to user_grade

if 9<=user_grade<=12:  #if statement checks if user_grade is between 9 and 12 inclusive

   print('in high school')  #displays this message when above if condition is true

else:  #when above if condition evaluates to false

   print('not in high school')#displays this message

Explanation:

If you want to take the user_grade from user as input then:

user_grade = int(input("Enter user grade: "))

if user_grade >=9 and user_grade <=12:

   print('in high school')

else:

   print('not in high school')

The expression

if user_grade >=9 and user_grade <=12:  

contains an if statement that checks a condition that can either evaluate to true or false. So the if condition above checks if the value of user_grade is between 9 and 12 inclusive.

Here the relational operator >= is used to determine that user_grade is greater than or equals to 9. relational operator <= is used to determine that user_grade is less than or equals to 12.

The logical operator and is used so both user_grade >=9 and user_grade <=12 should hold true for the if condition to evaluate to true. This means the user_grade should be between 9 and 12 (inclusive).

For example is user_grade = 10 then this condition evaluates to true as 10 is between 9 and 12 (inclusive). Hence the message: in high school is displayed on output screen.

But if user_grade= 13 then this condition evaluates to false because 13 is greater than 12. Hence the message: not in high school is displayed on output screen.

If user_grade = 8 then this condition evaluates to false because 8 is less than 9. Notice here that 8 is less than 12 so one part of the condition is true i.e. user_grade <=12 but we are using logical operator and so both the parts/expressions of the if condition should evaluate to true. This is why this condition evaluates to false. Hence the message: not in high school is displayed on output screen.

The screenshot of program and its output is attached.

Ver imagen mahamnasir

Following are the program to the given question:

Program Explanation:

  • Include header file.
  • Defining the main method.
  • Defining an integer variable "user_grade" that inputs the value from the user-end.
  • In the next step, a conditional statement is declared that checks the input value within "9 to 12", if the value is true it will use a print method that prints the user input value with a message.
  • Otherwise, it will print the value with the message.

Program:

#include <iostream>//header file

using namespace std;

int main()//main method

{

   int user_grade;//defining integer variable user_grade

   cin>>user_grade;//input user_grade value

   if(user_grade>9 && user_grade<12)//defining if block that check input value is between 9 to 12

   {

       cout<<user_grade<<" in high school";//print value with message

   }

   else//else block

   {

       cout<<"not in high school";//print value with message

   }

   return 0;

}

Output:

Please find the attached file.

Learn more:

brainly.com/question/16904233

Ver imagen codiepienagoya