5.25. Group Work: Functions and Conditionals

It is best to use a POGIL approach with the following. In POGIL students work in groups on activities and each member has an assigned role. For more information see https://cspogil.org/Home.

Note

If you work in a group, have only one member of the group fill in the answers on this page. You will be able to share your answers with the group at the bottom of the page.

Learning Objectives

Students will know and be able to do the following.

Content Objectives:

Process Objectives:

5.25.1. Basic Conditionals and Tests

Run this code to see what it prints.

Modify the code in the main method below to test all possible return values from get_temp_desc.

Put the blocks in order to define the function check_guess which will return 'too low' if the guess is less than the passed target, 'correct' if they are equal, and 'too high' if the guess is greater than the passed target. For example, check_guess(5,7) returns 'too low', check_guess(7,7) returns 'correct', and check_guess(9,7) returns 'too high'. There are three extra blocks that are not needed in a correct solution.

Finish the function last_half(str) which returns the last half of the characters from the passed string str. If str has less than 2 characters then return the empty string "". For example, last_half("a") returns "", last_half("coal") returns "al", and last_half("bye") returns ``ye.

Run this code to see what it prints. The modify it to work correctly. Next, add code to the main function to test each possible letter grade. It should return A if the score is greater than or equal 90, B if greater than or equal 80, C if greater than or equal 70, D if greater than or equal 60, and otherwise E.

5.25.2. Logical Operators and Complex Conditionals

The logical operators in Python are and, or, and not. These can be used to create complex conditionals.

Modify this code to use a complex conditional instead. It should still pass all tests. It should only take four lines of code or less.

Modify this code to use a complex conditional instead. It should still pass all tests. It should only take four lines of code or less.

Drag the blocks from the left and put them in the correct order on the right to define a function squirrel_play that takes a temp (the temperature) and Boolean is_summer that indicates if it is summer or not and returns True if it is summer and the temperature is between 60 and 100 (inclusive). It also returns True if it isn’t summer and the temperature is between 60 and 90 (inclusive). Otherwise, it returns False.

If you worked in a group, you can copy the answers from this page to the other group members. Select the group members below and click the button to share the answers.

The Submit Group button will submit the answer for each each question on this page for each member of your group. It also logs you as the official group submitter.

You have attempted of activities on this page