0% found this document useful (0 votes)
15 views1 page

While Loop FRQHW

The document provides a set of programming exercises for a Pre-AP Computer Science class focused on while loops. It includes tasks such as creating a countdown timer, summing numbers until a negative is entered, accumulating even numbers, validating a password, simulating bank withdrawals, and calculating a running average. Each task specifies the desired output and conditions for the while loops to be implemented.

Uploaded by

badolshikdar1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views1 page

While Loop FRQHW

The document provides a set of programming exercises for a Pre-AP Computer Science class focused on while loops. It includes tasks such as creating a countdown timer, summing numbers until a negative is entered, accumulating even numbers, validating a password, simulating bank withdrawals, and calculating a running average. Each task specifies the desired output and conditions for the while loops to be implemented.

Uploaded by

badolshikdar1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

Pre – AP Computer Science

While Loop Free Response HW

For the following questions, write the code that would satisfy the following questions.

1. Countdown Timer with Conditions Sample Output (if n = 5):


Write a while loop that starts from a given 5 - Odd number
number n and counts down to zero. If the 4 - Even number
current number is even, print "Even 3 - Odd number
number", and if it’s odd, print "Odd 2 - Even number
number." Once the counter reaches zero, 1 - Odd number
print "Liftoff!" Liftoff!

2. Sum Until Negative


Write a program that keeps asking the user for numbers and adds them to a total sum until a
negative number is entered. If the entered number is even, print "Added an even number," and if
it’s odd, print "Added an odd number." When a negative number is entered, end the loop and
print the total sum.

3. Even Numbers Accumulator


Create a while loop that starts at 20 and goes down to -2. For each number:
- If the number is even, add it to a total sum.
- If the number is odd, skip it.
- Print the sum once the loop completes.

4. Password Validator
Write a program that prompts the user to enter a password. If the password is incorrect, it should
keep asking for the password. If the password is "open123", print "Access Granted" and stop the
loop. If any attempt includes the word "exit", print "Exiting..." and stop the loop without granting
access.

5. Bank Withdrawal Simulator


Simulate a bank account with an initial balance of $500. Create a while loop that asks the user
for a withdrawal amount. If the amount is more than the balance, print "Insufficient funds" and
do not subtract from the balance. If the amount is less than or equal to the balance, subtract it and
print the new balance. Stop the loop when the balance is zero.

6. Running Average Calculator


Create a while loop that keeps asking the user for a number and calculates the running average. If
the user enters a zero, stop the loop and print the final average of all entered numbers. If the user
enters a negative number, skip that entry (do not add it to the average calculation).

You might also like