75.1k views
1 vote
Code Practice For this lesson, you will come up with your own challenging algorithm for other students to trace. It must contain at least 5 if statements and use at least one AND or OR boolean condition.

User Bienvenido
by
8.0k points

1 Answer

6 votes

Final answer:

An example of a challenging algorithm that contains at least 5 if statements and uses an AND or OR boolean condition is a program that determines the category of a given movie based on its rating and genre.

Step-by-step explanation:

An example of a challenging algorithm that contains at least 5 if statements and uses an AND or OR boolean condition is a program that determines the category of a given movie based on its rating and genre. Here's an example:



rating = 4.5
# Assuming the rating is on a scale of 1 to 5

genre = 'action'
# Assuming the genre can be 'action', 'comedy', or 'drama'

if rating > 4.0 and genre == 'action':
category = 'Highly Recommended Action Movie'
elif rating > 3.0 and (genre == 'action' or genre == 'comedy'):
category = 'Recommended Movie'
elif rating > 2.0 and genre != 'drama':
category = 'Decent Movie'
else:
category = 'Not Recommended'

print('Category:', category)



In this example, the program first checks if the rating is greater than 4.0 and the genre is 'action'. If both conditions are true, it assigns the category as 'Highly Recommended Action Movie'. Otherwise, it checks different combinations of rating and genre to determine the appropriate category.

User Majkel
by
8.4k points