Skip to content

Instantly share code, notes, and snippets.

"""
Practice Python 1st Exercise
Create a program that asks the user to enter their name and their age.
Print out a message addressed to them that tells them the year that they will turn 100 years old.
"""
import datetime
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu Jul 27 13:09:57 2017
@author: Jeff Garcia
Ask the user for a number. Depending on whether the number is even or odd,
print out an appropriate message to the user. Hint: how does an even / odd
number react differently when divided by 2?
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu Jul 27 13:33:46 2017
@author: Jeff Garcia
Take a list, say for example this one:
a = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu Jul 27 13:53:35 2017
@author: Jeff Garcia
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu Jul 27 14:41:13 2017
@author: Jeff Garcia
Take two lists, say for example these two:
a = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu Jul 27 15:05:44 2017
@author: Jeff Garcia
Let’s say I give you a list saved in a variable:
a = [1, 4, 9, 16, 25, 36, 49, 64, 81, 100]. Write one line of Python that
takes this list a and makes a new list that has only the even elements of
@jgarciabu
jgarciabu / Ex 8 Random Number Game.py
Created July 31, 2017 15:18
Random Number Game Ex 8
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Fri Jul 28 13:11:24 2017
@author: Jeff Garcia
Generate a random number between 1 and 9 (including 1 and 9). Ask the user to
guess the number, then tell them whether they guessed too low, too high, or
exactly right. (Hint: remember to use the user input lessons from the very
@jgarciabu
jgarciabu / Ex 10 Diff Size List Comparison.py
Created July 31, 2017 19:06
Ex 10 Diff Size List Comparison
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Author: Jeff Garcia
This week’s exercise is going to be revisiting an old exercise
(see Exercise 5), except require the solution in a different way.
Take two lists, say for example these two:
@jgarciabu
jgarciabu / Is Prime Ex 11.py
Created July 31, 2017 20:39
Is Prime Ex 11
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Ask the user for a number and determine whether the number is prime or not.
(For those who have forgotten, a prime number is a number that has
no divisors.). You can (and should!) use your answer to Exercise 4 to help you.
Take this opportunity to practice using functions, described below.
@author: Jeff Garcia
@jgarciabu
jgarciabu / First and Last Ex 12.py
Created July 31, 2017 20:50
First and Last Ex 12
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Write a program that takes a list of numbers (for example,
a = [5, 10, 15, 20, 25]) and makes a new list of only the first and last
elements of the given list. For practice, write this code inside a function.
@author: Jeff Garcia
"""
userlist = input("Please enter a list of numbers separated by a single space:")