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

cse160-staff@cs.washington.edu cse160_20au_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. In order to receive credit you MUST SIGN UP with your UWnetID email address (e.g. rea2000@uw.edu). 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
You should also add your name into the memo field as: Last Name, First Name and hit the "Update Memo" button.

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 Monday 10/12/20. 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!

You may find it useful to test your code out in PythonTutor. To do this you can cut and paste it into PythonTutor and then add a couple of calls to the function afterwards:

def sum_it(nums):

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

return count

print(sum_it([1, 2, 3])) print(sum_it([-1, 2, 0, 50]))

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 Wednesday October 14, 2020 11:59pm:
- BE SURE YOU ARE SIGNED IN before you attempt any problems! Otherwise you will have to log in and re-do them in order to get any credit
- 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  


Authoring docs

Copyright Nick Parlante 2017 - privacy