id/email
password
forgot password | create account
about | help | code help+videos | done | prefs
CodingBat code practice

cse160-staff@cs.washington.edu cse160_18sp_checkin01

We will use CodingBat to give you some practice writing small bits of Python. We will only assign a small number of problems but there are many here you can use to practice. We strongly recommend practicing as much as you can!

To use CodingBat and get credit for the participation assignments we will use it for, you NEED TO CREATE AN ACCOUNT. Do this in the upper right hand corner of this page. Please sign up with your UWnetID email address (e.g. rea2000@uw.edu) and use your real name (Last, First). After creating your account, in order to get credit for the exercises you do, you should select prefs from the upper right hand corner of this page and then select "Teacher Share" at the bottom of the page and enter this email address, followed by clicking the "Share" button:

cse160-staff@cs.washington.edu

In order to use CodingBat, you have to write your answers in the form of a function body. We will discuss functions in class on Wednesday 4/04/18. Here is all you need to know to do these problems.

To sum a list we would write:

nums = [3, 1, 2]

count = 0 for num in nums: count = count + num

print count

In CodingBat, you would write this as:

def sum_it(nums):

count = 0 for num in nums: count = count + num

return count

In CodingBat you would be given the first line ("def sum_it(nums):") which includes the name of the variable to use for the input (in this case there is only one input variable and it is called nums) and rather than printing the answer, you return it. This is actually filling out the body of a function. We will discuss input to functions and how return works in lecture on Wednesday but this should be enough to get you started!

Note: Since CodingBat is used for practicing Java as well as Python, there are a few slightly ugly things it does. 1) It uses the term "array" to refer to lists (e.g. [3, 5, 9]). 2) It uses the name "str" to refer to a variable that is a string. This is a bad name to use for a variable since we know we can also use the function str() to convert things to strings.

Please do these THREE problems by Sunday April 8, 11pm:
- Please sign up with your UWnetID and use your real name (Last, First)
- You must share your answers with teacher cse160-staff@cs.washington.edu under prefs in order to receive credit

sum_odds H   (Hint: Try this first: count_evens H  )
contains_hidden H  
count_z H  

---------------------------------

Here are a few suggested practice problems. Do as many of these as you like!

Warmups:
sleep_in H   diff21 H   near_hundred H   monkey_trouble H   parrot_trouble H   pos_neg H   sum_double H   makes10 H   string_times H   array_count9 H  

Strings:
hello_name H   make_abba H   make_tags  combo_string 

Lists:
make_pi  sum3  has23  count_evens H  

Ifs:
cigar_party H   date_fashion H   squirrel_play  caught_speeding  sorta_sum  alarm_clock  love6  in1to10 


Authoring docs

Copyright Nick Parlante 2017 - privacy