Question

PYTHON Implement a function called firstAndLast() that requests a nonempty list from the user and prints...

PYTHON

Implement a function called firstAndLast() that requests a nonempty list from the user and prints the first and last items in the list to the screen with the following messages:

>>> firstAndLast()

Enter a list: [1,2,3,4,5]

The first list element is 1

The last list element is 5

>>> firstAndLast()

Enter a list: [[1,2,3], [4,5,6], [7,8,9]]

The first list element is [1, 2, 3]

The last list element is [7, 8, 9]

0 0
Add a comment Improve this question Transcribed image text
Answer #1

def firstAndLast():
    lst = eval(input("Enter a list: "))
    print("The first list element is", lst[0])
    print("The last list element is", lst[-1])




Add a comment
Know the answer?
Add Answer to:
PYTHON Implement a function called firstAndLast() that requests a nonempty list from the user and prints...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Python Implement a program that requests from the user a list of words (i.e., strings) and...

    Python Implement a program that requests from the user a list of words (i.e., strings) and then prints on the screen, one per line, all four-letter strings in the list. >>> Enter word list: ['stop', 'desktop', 'top', 'post'] stop post

  • IN PYTHON Write a function called printDigits() that requests the user to input a four-digit integer...

    IN PYTHON Write a function called printDigits() that requests the user to input a four-digit integer and prints the digits using math function, as shown below. You are not allowed to process the number as a string. You must process the number using standard arithmetic operators (+, *, /, %, etc.) >>> printDigits() Enter n: 1234 1 2 3 4 >>> printDigits() Enter n: 9876 9 8 7 6 >>>

  • Using python Write a Python function called sgm that requests a positive integer n and returns...

    Using python Write a Python function called sgm that requests a positive integer n and returns the series geometric mean of the numbers 1,2,3, . . . n. For example sgm(5) = (5 x 4 x 3 x 2 x 1)1/5 = (120) 1/5 = 2.605 . Write the program so that a user is requested for a positive integer and program prints the series geometric mean of the integer. Example execution: Enter number: 5 series geometric mean of 5...

  • Implement the function odd_total (xs) that takes a list of list of ints xs and returns...

    Implement the function odd_total (xs) that takes a list of list of ints xs and returns the sum of the odd numbers but skips the numbers on the first row and the last column of xs. You're not allowed to modify xs. You can't use any built-in function or method except int, str, range and len. Example: odd_total ([[1,2,3],[4,5,6], [7,8,9]]) - - > 12

  • IN PYTHON Implement a function printSeqs() that accepts a list of name lst and prints the...

    IN PYTHON Implement a function printSeqs() that accepts a list of name lst and prints the following sequences. The sequences are printed by the for loops found in the function. The information below shows how you would call the function printSeqs() and what it would display: Write a for loop that iterates through a list of names and print a greeting for each name in the list. Request from the user a positive integer n and prints all the positive...

  • Implement a program that requests from the user a list of words (i.e., strings) and then...

    Implement a program that requests from the user a list of words (i.e., strings) and then prints on the screen, one per line, all four-letter strings in the list. >>> Enter word list: ['stop', 'desktop', 'top', 'post'] stop post An acronym is a word formed by taking the first letters of the words in a phrase and then making a word from them. For example, RAM is an acronym for random access memory. Write a function acronym() that takes a...

  • #Python 1.Write a function called difference() that accepts a list of numbers from the user and...

    #Python 1.Write a function called difference() that accepts a list of numbers from the user and returns the difference between the largest and the smallest numbers in the list as follows: >>> difference() Please enter a list: [100, 102, 106, -10] 116 >>> difference() Please enter a list: [1,2,3,4,5,6,7,8,9,10] 9 >>>

  • Implement a Python function that prints integers from a to b. The main part of the...

    Implement a Python function that prints integers from a to b. The main part of the program should ask the user to input a and b and call the function. # Display integers a, a+1, a+2, ..., b def display(a,b): ## complete your work here ## return a = int(input("Please prvide a value for a: ")) b = int(input("Please prvide a value for b: ")) display(a,b)

  • In python, Implement a function studentID() which allows the user to enter the 7-digit student ID....

    In python, Implement a function studentID() which allows the user to enter the 7-digit student ID. The program will keep prompting the user for a last name and first name. If the student does not have a student ID on record, the program will then ask for the student ID, and store that information. If the student already has a student ID, the program will display it, and ask for confirmation whether a new studentID should be assigned (and, if...

  • IN PYTHON Implement a function called printGreater() that accepts a list of numbers numLst and a...

    IN PYTHON Implement a function called printGreater() that accepts a list of numbers numLst and a number num. The function then iterates through the lst printing all numbers in the list that are greater than num. The results need to be printed on one line. >>> printGreater([200, 45, 270, 3, 7, 1000, 385, 20], 50) 200 270 1000 385 >>> printGreater([], 50) >>>

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT