Question: Unit 5: Accumulating Totals in a Loop in Python Summary: In this lab, you add a loop and the statements that make up the loop

Unit 5: Accumulating Totals in a Loop in Python

Summary:

In this lab, you add a loop and the statements that make up the loop body to a Python program. When completed, the program should calculate two totals: the number of left-handed people and the number of right-handed people in your class. Your loop should execute until the user enters the character X instead of a L for left-handed or a R for right-handed.

The inputs for this program are as follows: R, R, R, L, L, L, R, L, R, R, L, X.

Note that variables have been assigned for you, and the input and output statements have been written for you.

Instructions:

Make sure the file LeftOrRight.py is selected and open.

Write a loop and a loop body that allows you to calculate a total of left-handed and a total of right-handed people in your class.

Execute the program using the "Run Code" bottom at the bottom of the screen. Input the data listed above and verify that the output is correct.

Assignment:

"""

LeftOrRight.py - This program calculates the total number of left-handed and

right-handed students in a class.

Input: L for left-handed; R for right handed; X to quit.

Output: Prints the number of left-handed students and the number of right-handed students.

"""

rightTotal = 0 # Number of right-handed students.

leftTotal = 0 # Number of left-handed students.

leftOrRight = input("Enter an L if you are left-handed,a R if you are right-handed or X to quit.")

# Write your loop here.

for x in leftOrRight.split(", "):

if(x == 'L'):

leftTotal += 1

else:

rightTotal+=1

# Output number of left or right-handed students.

print("Number of left-handed students: " + str(leftTotal))

print("Number of right-handed students: " + str(rightTotal))

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!