Question

Python Program For this program the user should be able to enter multiple sequences of X,...

Python Program

For this program the user should be able to enter multiple sequences of X, Y, and Z characters. The sequences should all be the same length.

This program should output the average number and median number of X, Y, and Z characters for the set of sequences.

Example.

Input:

XYYZ

XYYZ

ZZZX

Output:

Average number of Xs: 1

Average number of Ys: 1.33

Average number of Zs: 1.66

Median number of Xs: 1

Median number of Ys: 2

Median number of Zs: 1

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

from statistics import median,mean

n = int(input("Enter number of sequence :"))

if n<=0:

    print("number of sequence should be positive")

else:

    seqs = []

    for i in range(n):

        seqs.append(input())

    # check all sequence have same length

    is_same = True

    l =  len(seqs[0])

    for s in seqs:

        if len(s) !=l:

            is_same = False

    if is_same == False:

        print("The sequences should all be the same length.")

    else:

        X = []

        Y = []

        Z = []

        for seq in seqs:

            x,y,z = 0,0,0

            for c in seq:

                if c == 'X':

                    x+=1

                if c == 'Y':

                    y+=1

                if c == 'Z':

                    z+=1

            X.append(x)

            Y.append(y)

            Z.append(z)

        print("Average number of Xs:","{0:.2f}".format(mean(X)))

        print("Average number of Ys:","{0:.2f}".format(mean(Y)))

        print("Average number of Zs:","{0:.2f}".format(mean(Z)))

        print("Median number of Xs:",median(X))

        print("Median number of Ys:",median(Y))

        print("Median number of Zs:",median(Z))

        

        

Add a comment
Know the answer?
Add Answer to:
Python Program For this program the user should be able to enter multiple sequences of X,...
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
  • This is Python The program should accept input from the user as either 7-digit phone number...

    This is Python The program should accept input from the user as either 7-digit phone number or 10-digit. If the user enters 7 characters, the program should automatically add "512" to the beginning of the phone number as the default area code. Dash (hyphen) characters do not count in input character count, but must not be random. If the user enters dashes the total character count must not exceed 12. The program should not crash if the user enters invalid...

  • Write the code in Python. The output should be exact the same as the given.

    Write the code in Python. The output should be exact the same as the given. Question 1. Study the examples below carefully and write a program for journal subscription Your program should work exactly as the following examples The text in bold indicates user input. Example 1: The user is a student, and the user subscribes to 2 journals Question 1 - Journal of Commodity Markets Journal of Sustainable Mining Journal of Asia-Pacific Biodiversity Student $21 $22 $27 Non-student $50...

  • 14.3: More Sentences Write a program that allows a user to enter a sentence and then...

    14.3: More Sentences Write a program that allows a user to enter a sentence and then the position of two characters in the sentence. The program should then report whether the two characters are identical or different. When the two characters are identical, the program should display the message: <char> and <char> are identical! Note that <char> should be replaced with the characters from the String. See example output below for more information. When the two characters are different, the...

  • PYTHON Write a program to enter a valid variable till the user wants to end. The...

    PYTHON Write a program to enter a valid variable till the user wants to end. The program should display the count of positive, negative, zeros and letters (upper and lower case)/symbols (error handling) entered. Based on the problem, you need to design an algorithm as follows: 1. Get the user input until “n” is entered 2. Add to the positive if it is greater than zero 3. Add to the negative if it is less than zero 4. Add to...

  • USING PYTHON - Write a program that calls a function that prompts the user to enter...

    USING PYTHON - Write a program that calls a function that prompts the user to enter a real number. The function should verify that the user entered a valid real number, and should prompt the user to re-enter any invalid input. After a valid real number has been entered, the function should return the number as a number. To test your function, from a main function, call the function two separate times and print the sum of the two numbers...

  • Write a PYTHON program that asks the user for the name of the file. The program...

    Write a PYTHON program that asks the user for the name of the file. The program should write the contents of this input file to an output file. In the output file, each line should be preceded with a line number followed by a colon. The output file will have the same name as the input filename, preceded by “ln” (for linenumbers). Be sure to use Try/except to catch all exceptions. For example, when prompted, if the user specifies “sampleprogram.py”...

  • Write a program that prompt the user to enter 3 integers: x,y and z. Your program...

    Write a program that prompt the user to enter 3 integers: x,y and z. Your program should output the answer to the user based on the divisibility of x and y by z as follows: Input If both x and y are divisible by z Result X and y are both divisible by 2. X is divisible by z. Y is divisible by z. Both X and Y are not divisible by If x is only divisible by z If...

  • Design a Python program that prompts the user to enter "yes" or "no" and validates the...

    Design a Python program that prompts the user to enter "yes" or "no" and validates the input. (Use a case-insensitive comparison) and another Python program that prompts the user to enter a number in the range of 1 through 100 and validates the input

  • Write a Python program to prompt the user for an integer number. Assign this integer to...

    Write a Python program to prompt the user for an integer number. Assign this integer to a variable X. Then assign a variable Y to the X**3 (X to the power 3). Finally, assign the variable Z to the square root of Y and print the values of X, Y, and Z as shown in the example below. Use main() function to define and call the program. Example: Enter an integer number: 3 X = 3 if Y=X**3 then Y...

  • Create a program in Python that will allow the user to enter a temperature in Fahrenheit...

    Create a program in Python that will allow the user to enter a temperature in Fahrenheit which will then be converted to degrees Celsius. The program will keep asking the user for a Fahrenheit temperature until the user enters Q to quit. After each conversion the program needs to print out the degrees Celsius. The input prompts for this problem need to look like the following: Degrees Fahrenheit: Continue: For these input prompts watch the capitalization and spacing. There are...

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