Skip to content

PythonADI/assignment-4-Megaduck14

Β 
Β 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

5 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Review Assignment Due Date

🐍 Python Assignment: Loops, Ranges, and String Manipulation

✨ Instructions:

Complete each of the tasks below. Each question is meant to help you practice working with for/while loops, the range() function, and controlling flow with continue and break, along with string operations like slicing and modification.


πŸš€ Task 1: Looping with range()

Print all numbers from 1 to 20 (inclusive) using a for loop and the range() function.

Bonus: Print only even numbers.


πŸ§ͺ Task 2: Skipping Items with continue

Loop through the numbers 1 to 10. Skip (do not print) the number 5 using continue.


β›” Task 3: Exiting a Loop with break

Loop through the numbers 1 to 10. Stop the loop when the number 7 is reached using break.


πŸ”„ Task 4: Capitalize Every Other Letter

Write a loop that takes a string and capitalizes every other letter, starting with the first.

Example: Input: "hello world" Output: "HeLlO WoRlD"


πŸ”‘ Task 5: Vowel Remover

Given a string, use a loop to remove all vowels (a, e, i, o, u) and print the result.

Example: "hello world" β†’ "hll wrld"


βœ‚οΈ Task 6: Stop at Special Character

Given a string, stop reading characters as soon as you hit a !. Use a loop and break.

Example: "hello! world" β†’ "hello"


Sure! Here's the updated Bonus Challenge β€” now a Guessing Game using loops and break:


🎯 Bonus Challenge: Number Guessing Game

Write a program that:

  • Chooses a secret number between 1 and 10 (you can set it manually for now, e.g., secret = 7)
  • Asks the user to guess the number in a loop
  • Tells the user if they guessed wrong
  • Ends the loop when the correct number is guessed (use break)
  • After a correct guess, prints "You got it!"
secret = 7  # You can change this or later use random.randint
while True:
    guess = int(input("Guess the number (1–10): "))
    
    # Your code here

use random.randint() to generate secret number

About

python-121-assignment-4-assignment-loops-2 created by GitHub Classroom

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%