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
  • 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 structured (procedural) Python program that solves the following spec: Soundex System Coding: Soundex is...

    Write a structured (procedural) Python program that solves the following spec: Soundex System Coding: Soundex is a system that encodes a word into a letter followed by three numbers that roughly describe how the word sounds. Therefore, similar sounding words have the same four-character code. Use the following set of (slightly modified #4) rules to create a translator from English words to Soundex Code: Retain the first letter of the word. For letters 2 …n, delete any/all occurrences of the...

  • 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 a recursive function called freq_of(letter, text) that finds the number of occurrences of a specified...

    Write a recursive function called freq_of(letter, text) that finds the number of occurrences of a specified letter in a string. This function has to be recursive; you may not use loops!   CodeRunner has been set to search for keywords in your answer that might indicate the use of loops, so please avoid them. For example: Test Result text = 'welcome' letter = 'e' result = freq_of(letter, text) print(f'{text} : {result} {letter}') welcome : 2 e and A list can be...

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