Question

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:

  1. Write a for loop that iterates through a list of names and print a greeting for each name in the list.
  2. Request from the user a positive integer n and prints all the positive divisors of n.
  3. Request from the user a list of months of the year. Use a for loop to print the abbreviation (first 3 characters) for each month in the list.
  4. Use for loops that will print the next four sequences shown below, each sequence on the same line and followed by a newline to separate sequences:

>>> printSeqs(['Mary', 'Bob', 'Connor', 'Taylor', 'Joan'])

Hello Mary. Welcome to CSC 241!

Hello Bob. Welcome to CSC 241!

Hello Connor. Welcome to CSC 241!

Hello Taylor. Welcome to CSC 241!

Hello Joan. Welcome to CSC 241!

We have greeted everyone!

Enter n for all positive divisors of n: 20

1

2

4

5

10

20

Please enter a list of months of the year: ['January', 'March', 'May', 'June', 'December']

Jan

Mar

May

Jun

Dec

The following four sequences are printed one per line.

0 1 2 3 4 5 6 7 8 9 10 11

3 4 5 6

0 3

5 9 13 17 21

>>>

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

def printSeq(lst):#definition fo function

    for i in lst:# for each element in list

        print("Hello ",i,". Welcome to CSC 241!")# prints statement

    n=int(input("Enter n for all positive divisors of n:"))#asks user for a number

    for i in range(1,n+1):# loop runs from 1 to 20

        if(n%i==0):# if number n fully divided by i then print i

            print(i)

    list=input("Please enter a list of months of the year:")# it asks user for a list of months

    list=list.split()# it splits the list

    for i in list:# for each element in list

        if(i[0]=="["):# if index of element contains "[" and if i[1] next index is " '" then prints the 3 characters

            if(i[1]=="'"):

                print(i[2:5])

        else:

            print(i[1:4])# if above condition false then print the 3 character

    print("the following four sequences are printed per line.")# print the statement

    s1=" 0 1 2 3 4 5 6 7 8 9 10 11 \n 3 4 5 6 \n 0 3 \n 5 9 13 17 21"# this contains numbers

    for i in s1:#for each in s1

          print(i,end="")# prints i

def printSeq (1st):#definition for i in 1st:# for each element in list fo function print (Hello ,i,. Welcome to CSC 241!)

  >>>printSegMary,Bob,Connor, Taylor Joan1) Hello Mary Welcome to CSC 241! Hello Bob Welcome to csC 241! Hello Connor W

Add a comment
Know the answer?
Add Answer to:
IN PYTHON Implement a function printSeqs() that accepts a list of name lst and prints the...
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
  • 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) >>>

  • 1) Translate the following equation into a Python assignment statement 2) Write Python code that prints...

    1) Translate the following equation into a Python assignment statement 2) Write Python code that prints PLUS, MINUS, O ZERO, depending on the value stored in a variable named N. 3) What is printed by: 3 - 1 while 5: while 10 Print ) Page 1 of 9 4) Write a Python while loop that reads in integers until the user enters a negative number, then prints the sum of the numbers. 1-2 of 9 4) Write a Python while...

  • 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]

  • For Python debugExercise12.py is a recursive function that accepts an integer argument, n, and prints the...

    For Python debugExercise12.py is a recursive function that accepts an integer argument, n, and prints the numbers 1 up through n. By debugging these programs, you can gain expertise in program logic in general and the Python programming language in particular. def main(): # Local variable number = 0 # Get number as input from the user. number = int(input('How many numbers to display? ')) # Display the numbers. print_num(number) # The print_num function is a a recursive function #...

  • In python using a def main() function, Write a function that will print a hello message,...

    In python using a def main() function, Write a function that will print a hello message, then ask a user to enter a number of inches (should be an integer), and then convert the value from inches to feet. This program should not accept a negative number of inches as an input. The result should be rounded to 2 decimal places(using the round function) and printed out on the screen in a format similar to the example run. Use a...

  • Python 3: Please follow the respective rubric for the following function definition. Rubric: Rectangle Shape You...

    Python 3: Please follow the respective rubric for the following function definition. Rubric: Rectangle Shape You should implement the following functions to print a rectangle shape. • print_rectangle(length, width, fillChar, hollow). This function will use draw_shape_line() function to print a rectangle shape with the given length and width, If the hollow is true, the shape will be hollow rectangle, otherwise a filled rectangle. This function must not interact with the user. For example, the call print_rectangle(5, 10, '*', False) should...

  • The problem is this Design a function that accepts a list as an argument and returns...

    The problem is this Design a function that accepts a list as an argument and returns the largest value in the list. The function should use recursion to find the largest item. My coding so far is this def main(): # Prints the largest value in list user_input = input('Enter a list of numbers seperated by a space: ') user_list = user_input.split() print('Largest number is ', max_Number(user_list), '.') # Recursion function that finds the maximum number in a sequence of...

  • c++ language 1) Create a function that prints a greeting when called with a name such...

    c++ language 1) Create a function that prints a greeting when called with a name such as greeting ("Elona") 2) Create a function that squares a double number and returns the result as a double. 3) Create a function that takes 5 int numbers and returns the average as a float 4) Create a single function that gives a greeting, calculates the average of 5 grades but does not return a value. Hint: Use return type void and a string...

  • PLEASE HELP! python code Problem 4. Define the function pythagorian_coprimes (n=100) that prints all pairs of...

    PLEASE HELP! python code Problem 4. Define the function pythagorian_coprimes (n=100) that prints all pairs of positive integer numbers (a, b) such that c = a + b is also a whole number and 1 <c<n. Include only those triples that are co-prime (do not have any common divisors other than 1). For example, (3, 4, 5) is okay but (30, 40, 50) should be skipped. Help: As a starting example, examine the function pythagorian_triples that yields all triples. Modify...

  • Student ID: 123 Write a C+ program with the following specifications: a. Define a C++ function (name it function_Student...

    Student ID: 123 Write a C+ program with the following specifications: a. Define a C++ function (name it function_StudentlD where StudentID is your actual student ID number) that has one integer input (N) and one double input (x) and returns a double output S, where N S = n 0 and X2 is given by 0 xeVn n 0,1 Хл —{2. nx 2 n 2 2 m2 x2 3 (Note: in the actual quiz, do not expect a always, practice...

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