Write an if-else statement with multiple branches. If givenYear is 2101 or greater, print "Distant future" (without quotes). Else, if givenYear is 2001 or greater (2001-2100), print "21st century". Else, if givenYear is 1901 or greater (1901-2000), print "20th century". Else (1900 or earlier), print "Long ago".

Respuesta :

#include <stdio.h>

int main(void) {

int givenYear;

givenYear = 1776;

if(givenYear >= 2100){

printf("Distant future");

}

else if (givenYear >= 2001){

printf("21st century");

}

else if (givenYear >= 1900){

printf("20th century");

}

else {

printf("Long ago");

}

return 0;

}

year = 2101

if year => 2101 then

print ("Distant future");

else if year => 2001 then

print ("21st Century");

else if year => 1901 then

print ("20th Century");

else if year <1901 then

print ("Long Ago");

Further Explanation

There are three types of conditionals in Python, which you can use to build a logic flow for your program. Python has the if, if..else, and if..elif..else statements.

To check conditions that do not meet the main conditions. Then else is used to handle all conditions other than the conditions that have been written.

If there are enough conditions to define, you can add other conditions by using the elif under the if statement and before the else statement.

And of course, a conditional can be stored in another if.

If Else condition

Decision making (if-else conditions) is not only used to determine what actions will be taken in accordance with the conditions but also is used to determine what actions will be taken/carried out if the conditions are not appropriate.

In python, there are several statements/conditions including if, else and elif The if the condition is used to execute code if the condition is true.

The condition if-else is a condition where if the statement is true True then the code in if will be executed, but if it is false False it will execute the code in else.

Learn More

if-else statement https://brainly.com/question/10798332

Conditional if in python https://brainly.com/question/10798332

Detail

Class: High School

Subject: Computers and Technology

Keyword: If-Else, Python, Code