Question

Write Python statements corresponding to the following: (a) assign to variable numYes the number of occurrences...

Write Python statements corresponding to the following:
(a) assign to variable numYes the number of occurrences of 'Y' in list answers.
(b) assign to variable numNo the number of occurrences of 'N' in list answers.
(c) assign to variable percentYest the percentage of strings in answers that are 'Y'.
(d) sort the list answers.
(e) Assign to variable f the index of the first occurrence of 'Y' in sorted list answers.

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

Please let me know in case of any issue.

Assuming answers= ['Y','N','N','Y','N','Y','Y','Y','N','N','N']

numYes = 0
numNo = 0

for k, val in enumerate(answers):
if( val == 'Y'):
numYes = numYes + 1
elif(val == 'N'):
numNo = numNo + 1

print "Number of 'Y': ", numYes
print "Number of 'N': ", numNo

percentYest = float(numYes)/len(answers)

print "Percentage of 'Y': ",percentYest

answers.sort()

for k, val in enumerate(answers):
if(val == 'Y'):
print "First index of 'Y': ", k
break

Add a comment
Know the answer?
Add Answer to:
Write Python statements corresponding to the following: (a) assign to variable numYes the number of occurrences...
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 code: 1. This question practices the use of a list method. Assign to the variable...

    Python code: 1. This question practices the use of a list method. Assign to the variable grades a list of 10 letter grades from among ‘A’, ‘B’, ‘C’, ‘D’, and ‘F’. For example: grades = [‘A’, ‘F’, ‘C’, ‘F’, ‘A’, ‘B’, ‘A’, ‘C’, ‘A’, ‘B’] Write a Python expression that creates a list named frequency, in which the elements are the number of times each of the letters A, B, C, D and F appear in grades. For example, for...

  • Write a Python if statement that calls doWhat() if a and b is true or a...

    Write a Python if statement that calls doWhat() if a and b is true or a and not c is true or e is equal to q. Write an example of a Python for loop that uses a range. Write an example of a Python for loop that iterates on the members of a container such as a list. Show by code example in Python how to concatenate two strings and assign the result to a variable.

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

  • The random variable x is the number of occurrences of an event over an interval of...

    The random variable x is the number of occurrences of an event over an interval of ten minutes. It can be assumed that the probability of an occurrence is the same in any two time periods of an equal length. It is known that the mean number of occurrences in ten minutes is 5.4. What is the appropriate probability distribution for the random variable? a)continuous b)either discrete or continuous depending on how the interval is defined c)binomial d)discrete

  • USE Python 1. Assign value 555 to the variable x, write code to square the variable...

    USE Python 1. Assign value 555 to the variable x, write code to square the variable x and print out the result. 2. Given a string x, write a program to check if its first character is the same as its last character. If yes, the code should output "True" . 3. We defined two variables, x = 'Python' and y = '3.0'. Write code to concatenate the two numbers (the result should be 'Python3.0').

  • 1) Which of the following is NOT true about a Python variable? a) A Python variable...

    1) Which of the following is NOT true about a Python variable? a) A Python variable must have a value b) A Python variable can be deleted c) The lifetime of a Python variable is the whole duration of a program execution.   d) A Python variable can have the value None.        2) Given the code segment:        What is the result of executing the code segment? a) Syntax error b) Runtime error c) No error      d) Logic error 3) What...

  • Write a Java program for all items in Question Use System.out.println() for each resulting string. Let...

    Write a Java program for all items in Question Use System.out.println() for each resulting string. Let s1 be " Welcome " and s2 be " welcome ". Write the code for the following statements: a. Check whether s1 is equal to s2 and assign the result to a Boolean variable isEqual. b. Check whether s1 is equal to s2, ignoring case, and assign the result to a Boolean variable isEqual. c. Compare s1 with s2 and assign the result to...

  • Write Python expressions corresponding to the following statements: The length of the hypotenuse in a right...

    Write Python expressions corresponding to the following statements: The length of the hypotenuse in a right triangle whose other two sides have lengths a and b The value of the expression that evaluates whether the length of the above hypotenuse is 5 The area of a disk of radius a The value of the Boolean expression that checks whether a point with coordinates x and y is inside a circle with center (a, b) and radius r

  • Write a program(Python language for the following three questions), with comments, to do the following:   ...

    Write a program(Python language for the following three questions), with comments, to do the following:    Ask the user to enter an alphabetic string and assign the input to a variable str1. Print str1. Check if str1 is valid, i.e. consists of only alphabetic characters. If str1 is valid Print “<str1> is a valid string.” If the first character of str1 is uppercase, print the entire string in uppercase, with a suitable message. If the first character of str1 is...

  • Write Python statements to create the following Python lists (to submit this, copy paste your answers):...

    Write Python statements to create the following Python lists (to submit this, copy paste your answers): I need help with these problems. 1. List of 5 or more colors 2. List of your friends on our college campus (first names ok) 3. List of first names of your family members 4. List of 5 or more grocery items that you need to purchase to prepare dinner tonight 5. List of the following characters: A, E, I, O, U

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