Prior instructions for Session 11 created the following: - A list variable containing numbers named grades - A list variable containing strings named fish - A string variable named song1 - A number variable named total (contains a float number with a fraction) - A number variable named score (contains an integer without a fraction) FOR statements involve a sequence that determines how many times a loop will repeat. Which of the following FOR statements have a valid sequence? Question 8 options: a) for item in range(5): b) for item in range(total): c) for item in grades: d) for item in song1: e) for item in range(song1): f) for item in range(grades): g) for item in total: h) for item in score: i) for item in fish:
Added by Renee H.
Step 1
Step 1: The valid FOR statements are those that have a sequence that can be iterated over. Show more…
Show all steps
Your feedback will help us improve your experience
Supreeta N and 63 other AP CS educators are ready to help you.
Ask a new question
Labs
Want to see this concept in action?
Explore this concept interactively to see how it behaves as you change inputs.
Key Concepts
Recommended Videos
Texts: Write a Python program that will incorporate conditional looping to average a given number of assignment grades for a student. The program will calculate and display the average. Pseudocode: 1. Enter the number of grades to process. 2. Enter a student name. 3. While the loop counter is less than the number of grades to process: - Enter an assignment grade. - Add the grade to the grade tally. - Increment the loop counter. 4. Calculate the student's average. 5. Display the student's average. Assignment Instructions: 1. Initialize variables as needed (i.e., numGrades = 0). - Reference: Refer back to "Learn to Program With Python 3: A Step-by-Step Guide to Programming, 2nd edition, Chapter 2: Booleans." 2. Prompt the user to input the number of grades to be processed. Store this value in a variable (i.e., numGrades). - Hint: This value will determine how many repetitions are performed. - Reference: Refer back to your Unit 1 readings in "Learn to Program With Python 3: A Step-by-Step Guide to Programming, 2nd edition, Chapter 3: Built-In Functions / Getting Input From the User." 3. Prompt the user to enter a student name. Store that name in a variable (i.e., studentName). 4. Create a conditional loop and continue processing grade values for this student until the given number of assignments have been processed. - Within this loop: - Prompt to get a numeric grade value from the user. - Add that grade to a numeric variable to keep a tally of the grades. Each time through the loop (for a given student), a new grade value will be entered and added to this tally. - Increment the loop counter. 5. Once grades for the conditional loop have been entered, average the grades using the total tally divided by the number of grades to be entered given at the start of the program. Store the average in a variable (i.e., studentAverage). - Reference: Refer back to your Unit 2 readings in "Learn to Program With Python 3: A Step-by-Step Guide to Programming, 2nd edition, Chapter 2: Simple Math." 6. Display the name of the student and their average. EXAMPLE OUTPUT Enter the number of grades to process: 2 Enter student name: Bob Enter assignment grade: 90 Enter assignment grade: 80 Bob has an average of: 85.0
Supreeta N.
HW2c: if Statements, Lists, and for Loops - PYTHON Coding Using Python, write a program, hw2c.py, that meets the following requirements: 1. Allows the entry of a student's name. 2. Allows the user to enter the number of grades. 3. Allows the user to enter that (see #2) number of grades. 4. Stores these grades in a list. 5. Calculates the average of the entered grades. 6. Assigns the letter grade to the calculated average (use standard grade assignments such as 90-100 is an A, 80-89 is a B, and so on). 7. Outputs the following (see sample output): - Student's name - A list of the grades entered - Assignment average - Letter grade Sample Output: Tyrone, the 3 grades you entered are below: - Grade 1: 97 - Grade 2: 85.5 - Grade 3: 79 The average is 87.2% or a "B" Comment the hw2c.py code given the software requirements. Be sure to use the commenting style - comment each line of code identifying what step it is and defining/explaining what it is doing or its purpose.
Akash M.
Follow these steps: ● Imagine you are running a cafe. Create a new Python file in your folder called cafe.py. ● Create a list called menu, which should contain at least four items sold in the cafe. ● Next, create a dictionary called stock, which should contain the stock value for each item on your menu. ● Create another dictionary called price, which should contain the prices for each item on your menu. ● Next, calculate the total_stock worth in the cafe. You will need to remember to loop through the appropriate dictionaries and lists to do this. Tip: When you loop through the menu list, the ‘items’ can be set as keys to access the corresponding ‘stock’ and ‘price’ values. Each ‘item_value’ is calculated by multiplying the stock value by the price value. For example: item_value = (stock[items] * price[items]) ● Finally, print out the result of your calculation.
Patina H.
Recommended Textbooks
Computer Science and Information Technology
Introduction to Programming Using Python
Computer Science - An Overview
Transcript
18,000,000+
Students on Numerade
Trusted by students at 8,000+ universities
Watch the video solution with this free unlock.
EMAIL
PASSWORD