Module 7: Lab Activity – While Loops


Python programs for the following problems. Use the names listed below:





Be sure to upload your code to Github as well.


All submitted code must include appropriate comments.


Problem 1: Write an infinite while loop that prints “Infinite” an infinite number of times.


Problem 2: Re-write Module 6 Lab Activity Problem 1 using a while loop instead of a for loop. Remember to initialize a counter variable to keep track of how many times your loop has run.


Problem 3: Write a program that takes a user input, then uses a while loop to check if that input is the letter A, B, or C. The loop should continue until a valid input is entered by the user. Bonus: Allow the input to be correct regardless of case, so either 'A' or 'a' is valid. The upper() and lower() functions should help.


Problem 4: Write a program that implements the following:

Imagine you're an archer in a competition. You have 10 arrows you can shoot to score the most points possible.

1. Create a variable to represent your total score. Set its initial value to 0.

2. Create a variable to represent the number of arrows you have. Set its initial value to 10.

3. Create an empty list to represent your score card.

4. While you still have at least one arrow left to shoot:

a. Generate a random number between 0 and 10 to represent where on the target you managed to hit.

i. Append this number to your score card list.

b. If the number is 10, you got a bullseye! Increase your score by 20 points, then subtract 1 from your remaining arrows. Tell the user that they got a bullseye.

c. Otherwise, if the number is between 1 and 9, increase your score by the random number you generated, then subtract 1 from the remaining arrows.

d. Otherwise, if the number is 0, you earn no points, but don't lose an arrow. Tell the user that they missed.


5. Once you're out of arrows, print the final score and the score card along with a message to the user.


Need a custom answer at your budget?

This assignment has been answered 4 times in private sessions.

© 2021 Codify Tutor. All rights reserved