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...

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

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

  • Use C programming Make sure everything works well only upload Write a program that takes an...

    Use C programming Make sure everything works well only upload Write a program that takes an integer from standard input and prints all prime numbers that are smaller than it to standard output. Recall that a prime number is a natural number greater than 1 whose only positive divisors are 1 and itself. At the start of the program, prompt the user to input a number by printing "Input a number greater than 2:\n". If the user's input is less...

  • 2. Pointer arithmetic: a) Write a printString function that prints a string (char-by-char) using pointer arithmetics...

    2. Pointer arithmetic: a) Write a printString function that prints a string (char-by-char) using pointer arithmetics and dereferencing. b) Write a function “void computeMinMax(double arr[], int length, double * min, double * max)” that finds the minimum and the maximum values in an array and stores the result in min and max. You are only allowed to use a single for loop in the function (no while loops). Find both the min and the max using the same for loop....

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
ADVERTISEMENT