CSC148H5 Lecture Notes - Lecture 10: University Of Toronto Mississauga, Binary Code, Empty String
Document Summary
Csc148h5s - introduction to computer science (winter 2017) After you learn it, you don"t think about computer science in the way as before. Anything you can solve with recursion can be solved using a loop too. Recursion: powerful problem-solving technique for helping us solve difficult problems. # example without recursion def fact (n): total = 1 for i in range(n+ 1 ): return total total = total * i. Binary code - a string of 0s and 1s ex. "11100" , "0100011" , "" , "0" , "1" also called binary string. We"re going to be given an integer r, and we want to generate all binary code of length r. def codes (r): ["00","01","10","11"] # 4 binary codes of length 2. >>> codes(1) # all binary codes of length 1. >>> codes(0) #all binary codes of length 0. # cannot be empty list [], there is one binary string of length. >>> codes(3) #all binary codes of length 3.