Exercises¶
- Write code to assign the string
"You can apply to SI!"
tooutput
if the string"SI 106"
is in the listcourses
. If it is not incourses
, assign the value"Take SI 106!"
to the variableoutput
.
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
.
- Create a variable,
b
, and assign it the value of15
. Then, write code to see if the valueb
is greater than that ofa
. If it is,a
’s value should be multiplied by 2. If the value ofb
is less than or equal toa
, nothing should happen. Finally, create variablec
and assign it the value of the sum ofa
andb
.
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
.
- Create one conditional to find whether “false” is in string
str1
. If so, assign variableoutput
to the string"False. You aren't you?".
Otherwise, if “true” is in stringstr1
. If so, assign variableoutput
to “True! You are you!”. If neither are instr1
, assignoutput
to “Neither true nor false!”
3.1
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
.
- 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 variablenum_words
so thatnum_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.
- We have created conditionals for you to use. Do not change the provided conditional statements. Find an integer value for
x
that will causeoutput
to hold the valuesTrue
andNone
. (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"
.
- 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
andlower
. Assign each course inclasses
to the correct list,upper
orlower
. HINT: remember, you can convert some strings to different types!
- 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 calledpast_tense
.