Created
July 31, 2017 20:50
-
-
Save jgarciabu/45e436b2c87cf067ac669014932b2fde to your computer and use it in GitHub Desktop.
First and Last Ex 12
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:") | |
userlist = list(map(int,userlist.split())) | |
def list_first_and_last(userlist): | |
newlist = [] | |
newlist.append(userlist[0]) | |
newlist.append(userlist[-1]) | |
return newlist | |
print(list_first_and_last(userlist)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment