Exercises

  1. Write code to assign the string "You can apply to SI!" to output if the string "SI 106" is in the list courses. If it is not in courses, assign the value "Take SI 106!" to the variable output.

1.1 Write code so that if "STATS 250" is in the list schedule, then the string "You could be in Information Science!" is assigned to the variable resp. Otherwise, the string "That's too bad." should be assigned to the variable resp.

  1. Create a variable, b, and assign it the value of 15. Then, write code to see if the value b is greater than that of a. If it is, a’s value should be multiplied by 2. If the value of b is less than or equal to a, nothing should happen. Finally, create variable c and assign it the value of the sum of a and b.

2.2 Create the variable z whose value is 30. Write code to see if z is greater than y. If so, add 5 to y’s value, otherwise do nothing. Then, multiply z and y, and assign the resulting value to the variable x.

  1. Create one conditional to find whether “false” is in string str1. If so, assign variable output to the string "False. You aren't you?". Otherwise, if “true” is in string str1. If so, assign variable output to “True! You are you!”. If neither are in str1, assign output to “Neither true nor false!”

3.1

Create a conditional structure in this code box below the assignment of w, so that if the string "Friendly" is in w, then "Friendly is here!" should be assigned to the variable wrd. If that’s not the case, your code should check if the string "Friend" is in w. If it is, the string "Friend is here!" should be assigned to the variable wrd. Otherwise, assuming neither of those things are true, the string "No variation of friend is in here." should be assigned to the variable wrd. (Also consider: does the order of your conditional statements matter for this problem? Why?)

4 Create an empty list called resps. Using the list percent_rain, for each percent, if it is above 90, add the string ‘Bring an umbrella.’ to resps, otherwise if it is above 80, add the string ‘Good for the flowers?’ to resps, otherwise if it is above 50, add the string ‘Watch out for clouds!’ to resps, otherwise, add the string ‘Nice day!’ to resps.

  1. For each word in list words, find the number of characters in the string. If the number of characters in each string is greater than 3, add 1 to the variable num_words so that num_words should end up with the total number of words with more than 3 characters.

5.1 For each string in wrd_lst, find the number of characters in the string. If the number of characters is less than 6, add 1 to accum so that in the end, accum will contain an integer representing the total number of words in the list that have fewer than 6 characters.

  1. We have created conditionals for you to use. Do not change the provided conditional statements. Find an integer value for x that will cause output to hold the values True and None. (Drawing diagrams or flow charts for yourself may help!)

6.1 We have written conditionals for you to use. Create the variable x and assign it to some integer so that at the end of the code, output will be assigned the string "Consistently working".

  1. Challenge In XYZ University, upper level math classes are numbered 300 and up. Upper level English classes are numbered 200 and up. Upper level Psychology classes are 400 and up. Create two lists, upper and lower. Assign each course in classes to the correct list, upper or lower. HINT: remember, you can convert some strings to different types!
  1. For each word in words, add ‘d’ to the end of the word if the word ends in “e” to make it past tense. Otherwise, add ‘ed’ to make it past tense. Save these past tense words to a list called past_tense.
Next Section - Extra Exercises