Discussion
general python
list comprehensions
class stuff
code writing
100

What is casting

Casting, also known as type conversion, is a process that converts a variable's data type into another data type

100

name a built in method

.split()


if you said something like print(), you'd be wrong because methods are functions that instances of a class run on themselves

100

Write a list comprehension that gives me the even numbers within [0-10] (that's inclusive)

[i for i in range (0, 11) if i%2==0]

100

What's the syntax of defining a class?

class ClassName:

    #code in here

100

Write a dictionary correlating last names(items) to first names (keys) for George Lopez, Arianna Grande, and Taylor Swift

{'George': 'Lopez',
'Arianna': 'Grande',
'Taylor': 'Swift'}

200

What's the point of functions?

You use functions in programming to bundle a set of instructions that you want to use repeatedly or that, because of their complexity, are better self-contained in a sub-program and called when needed.

200

What's a list inside a list called

A nested list

200

list comprehension of everything in the list "stuff = ['a', 'b', 'aa', 'ca', 'ya' ,'b']" that starts with 'a'

[entry for entry in stuff if entry[0] == 'a']

200

What method runs upon instantiation of a class?

__init__(self)

200

write a function that takes in a str and returns the vowels. Only count Y if it's the last letter

def vowel_count(word):

   count = 0

   for letter in word:

      if letter in 'aeiou':

          count+=1

    if word:

       if word[-1] == 'y':

          count +=1

   return count

300

What's the point of making classes?

To encapsulate different types of data

300

name 5 iterable types

range, list, tuple, dict, set (yes, it is iterable)

300

using the following function:

def is_prime(n): #feel free to make use of this function

  for i in range(2,n):

    if (n%i) == 0:

      return False

  return True
make a list comp. of primes up to 1000

[num for num in range(1000) if is_prime(num)]

300

in the scope of a method, what's "self" mean

self refers to the instance of the class that's running the method. It is the specific member

300

Write a function that changes a float to the next nearest whole number n

round(n)

400

what is data hiding and how is it used

Data hiding in Python is the method to prevent access to specific users in the application. Used by placing an underscore in front of a variable

400

give an example of a keyword argument for a built-in-function

end (for print), sep (also for print)

400

give a list comprehension of all the powers of 2, but negate one from each result

[(2**num)-1 for num in range (10)]

400

Which function utilizes the __str__ function?

print()

400

take a random number out of this list and return it in one line of code (random is imported), but the number must be divisible by 3

list1 = [1, 4, 6, 3]

import random

return random.choice([num for num in list1 if num%3==0])

500

What does object oriented programming have to do with Python?

Object-oriented programming (OOP) is a computer programming model that organizes software design around data, or objects, rather than functions and logic. Most things in Python are objects, including functions, variables, and and instance of a class

500

name the argument types
(a, b, /, c, d, *, e, f)

a, b are positional

c, d are flexible

e, f are keyword-only

500

using a nested list comprehension, find all the lengths of the numbers divisible by 13 that are under 2000

[len(str(num)) for num in [i for i in range(2000) if i%13==0]]

500

write the line to import the class named "CoolGuy" from the file dope.py

from dope import CoolGuy
500

 -- DOUBLE JEOPARDY -- (that means double points)

write a pokemon class that has a dictionary of movenames with items corresponding to damage. Write a method that attacks another pokemon by choosing a random move and negating it from the other pokemon's health stat

import random

class Pokemon:

   def __init__(self):

      attacks = {}

      health = 100

   def attack(self, other):

       attackkey = random.choice(self.attacks.keys())

       other.damage(self.attacks[attackkey])

   def damage(self, hurtpoints):

       self.health -= hurtpoints

 

M
e
n
u