1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
murzikaleks [220]
3 years ago
12

Write an expression that will print "in high school" if the value of user_grade is between 9 and 12 (inclusive). Sample output w

ith input: 10 in high school

Computers and Technology
1 answer:
Strike441 [17]3 years ago
7 0

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.

You might be interested in
in python i wrote a function where if the user inputs a certain word the function repeats over again, since the function aaks fo
Colt1911 [192]
Check out the counter set
4 0
2 years ago
What kind of operating system is Windows? Command-line Browser based Graphical user interface Linux-based
snow_tiger [21]
Graphical user interface
4 0
3 years ago
Read 2 more answers
Which design principle will help me add an element of interest in my poster by avoiding confusion and monotony?
Rasek [7]

Answer:

You could add pictures to help convey the viewer, while capturing their attention. It will provide great interest as well.

Explanation:

Me being a viewer, I love to see pictures. They help explain the topic, while keeping my attention.

7 0
3 years ago
How many threads can a quad-core processor handle at once?
Hoochie [10]
It can handle 8 threads at once.
4 0
3 years ago
A(n) ____ network uses a central cable to which all network devices connect.
NNADVOKAT [17]
<span>A bus network uses a central cable to which all network devices connect</span>
4 0
3 years ago
Other questions:
  • Which software would you use to create a print design?
    8·2 answers
  • ​______________________ is a general security term that includes computer​ viruses, worms, and trojan horses.
    13·1 answer
  • If an occupation is projected to decline by 7% over the next 10 years, how would you rate the job outlook?
    12·1 answer
  • Create a function called "strip_r_o" that takes in a STRING and strips all the Rs and Os from the string. Also use a FOR loop in
    7·1 answer
  • Conduct a site research on a specific property using the concepts discussed during this week.
    11·1 answer
  • The default for automatic replies in outlook is what?
    6·2 answers
  • Write a program to find the sum of first 10 even numbers in qbasic​
    15·1 answer
  • The TCP _____ is the amount of information that a machine can receive during a session and still be able to process the data.
    5·1 answer
  • चार फरक छुट्याउनुहोस् ।) 3. Write down any four provisions of cyber ethic साइबर नैतिकताका कुनै चार प्रावधानहरु लेख्नुहोस् ।​
    11·1 answer
  • 3. is the system of rules that govern the ordering of values? culture a. Ethics b. organization c. protocol d. value system 3 .
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!