This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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:") |
OlderNewer