Thursday, December 4, 2014

1.3.6 Activity response: lists and tuples

Hilariously, I only used lists to test the second function despite the lesson being on lists and tuples.

import random
def roll_two_dice():
    a = random.randint(1,6)
    b = random.randint(1,6)
    return a+b

def guess_letter():
    letters = 'abcdefghijklmnopqrstuvwxyz'
    return letters[random.randint(0,len(letters)-1)]

Question answers:

  1. A can be printed and concatenated as a standard string, B can be appended and store different string lengths in each element, and C can only be read from.
  2. Languages have different variable types because different variables' contents are incompatible by nature.  "A" + 32 + True - (1,2,3) = ????
  3. Technically speaking, everything COULD be represented as integers since computers store everything as 1s and 0s anyways, but using integers to store a string would be incredibly difficult and inefficient.

No comments:

Post a Comment