Skip to content

Instantly share code, notes, and snippets.

View kenini's full-sized avatar

Teri kenini

  • London, ON Canada
View GitHub Profile
@kenini
kenini / Exercise5.py
Created January 17, 2019 17:25
Python practice
#Take two lists and write a program that returns a list that contains only the elements that are common between the lists (without duplicates). Make sure your program works on two lists of different sizes.
a = [1,2,3,4,5,6,5,6,5,4,5,6]
b = [5,6,7,8,9,0,9,78,5,6,45]
c = []
for a1 in a:
if a1 in b:
c.append(a1)
@kenini
kenini / Exercise4.py
Created January 14, 2019 21:42
Python Practice
#Create a program that asks the user for a number and then prints out a list of all the divisors of that number. (If you don’t know what a divisor is, it is a number that divides evenly into another number. For example, 13 is a divisor of 26 because 26 / 13 has no remainder.)
num = int(input("Please choose a number to divide: "))
numRange = range(1, num+1)
for a in numRange:
if num % a == 0:
print(a)
@kenini
kenini / Exercise3.py
Created January 14, 2019 21:10
Python Practice
#Make a list and write a program that prints out all the elements of the list that are less than 5.
#Extras:
#Instead of printing the elements one by one, make a new list that has all the elements less than 5 from this list in it and print out this new list.
#Write this in one line of Python.
#Ask the user for a number and return a list that contains only elements from the original list a that are smaller than that number given by the user.
b = []
a = [1,2,3,4,5,6,7,8,9,10]
for a1 in a:
if a1 < 5:
@kenini
kenini / Exercise2.py
Created January 11, 2019 19:06
Python practice
#Ask the user for a number. Depending on whether the number is even or odd, print out an appropriate message to the user.
#Extras:
#If the number is a multiple of 4, print out a different message.
#Ask the user for two numbers: one number to check (call it num) and one number to divide by (check).
#If check divides evenly into num, tell that to the user. If not, print a different appropriate message.
num = int(input("Pick a number: "))