EE1021 Lecture 2 Homework: Strings, Input and Control Flow

Topics: strings & slicing, basic input, if/elif/else, for & while loops

Workflow: predict or outline first, implement in VS Code, test with at least two inputs, and explain any correction you made. Bring questions to the next practice session.

Core work: A1–A2, B1–B2, C1–C2, D1–D2, and E1. Extension work: A3, B3, C3, D3, E2–E3, and Section F.

How to submit

This homework is not graded, but you must submit it on CATS. Your instructor checks who worked on it. Check CATS for the due date.

  1. Download the answer template EE1021_L02_Homework_Template.py from the CATS assignment.
  2. Rename it to EE1021_L02_<student number>.py. Example: EE1021_L02_2500001234.py.
  3. Write each answer inside its own block in the file. The line RUN = "A1" at the top chooses which problem runs. Change it to test one problem at a time.
  4. Under each problem, paste the output of one test run as comments (#). For input problems, include what you typed.
  5. Write your explanations and the Reflection answers as comments too.
  6. Run the file once for every problem you answered. It must run without errors.
  7. Submit only the .py file on CATS. Do not submit a Word or PDF file.

Do the core problems. The extension problems are optional. Do not use lists or functions you write yourself; they come in later weeks. It is fine if some answers are not correct. Submit what you have and write one comment about what went wrong. You may discuss ideas with classmates, but write your own code.


Section A – Strings in Action

  1. Use the variables below and string concatenation to print the sentence EE1021 meets on Tuesday at 08:30 in Lab 204.

    course_code = "EE1021"
    meeting_day = "Tuesday"
    room = "Lab 204"
    start_time = "08:30"

    Write the print statement(s) you used and copy the output.

  2. Given quote = "Engineers solve problems, coders craft tools.", do each task without hard-coding the answers:

    • slice the substring containing characters with indices 10 through 24 (inclusive)
    • print every third character starting from index 1 For each result, note the slice or logic you relied on.
  3. Turn phrase = "Prototype Verified Successfully" into the acronym PVS using a loop. Hint: build a new string by taking the first letter after each space (and the very first character). Note: You do not need any string methods; use indexing on the original text.


Section B – Input and Conversion

  1. Ask the user for the width and height of a poster in centimeters (floats). Calculate the area in square meters and display it with a message such as Area in square meters: 0.72. Show a sample interaction.

  2. Read a temperature in Celsius from the user. Convert it to Fahrenheit and Kelvin, then print all three values on one line using commas to separate them.

  3. Prompt the user for the total number of minutes they studied in a week. Convert this to whole hours and remaining minutes (e.g., 125 minutes -> 2 hours 5 minutes) and display the result.


Section C – Decision Making

  1. Ticket kiosk: ask for a visitor’s age and whether they have a student card ("y"/"n"). Ticket prices are: ages under 6 → free, 6–17 → 8 TL, 18 and above → 12 TL, but students 18+ pay 9 TL. Print the ticket price or an error if the age is negative.

  2. Lift check: a small lift is rated for 400 kg and 5 people. Its safe zone is 300 kg and 4 people or less. Write a program that reads two integers: load_kg (the total weight in the lift, people included) and people. Display:

    • Invalid input if either value is negative
    • Safe if load_kg <= 300 and people <= 4
    • Caution if load_kg <= 400 and people <= 5
    • Over limit otherwise Test the program with at least one boundary value (such as 300, 301, 400, or 401), and with load_kg = 200 and people = 6. Briefly explain how your if/elif/else structure guarantees that only one message appears.
  3. Ask for a month number (1–12) and print the corresponding season in English: Winter, Spring, Summer, or Autumn. Handle invalid inputs (e.g., 0 or 15) with a helpful message.


Section D – for Loop Practice

  1. Use a for loop and range to print the numbers from 4 to 20 stepping by 4. While looping, keep a running total of these numbers and print the final sum when the loop finishes.

  2. Create a program that prints the first 10 multiples of 5 on a single line separated by spaces. After printing the sequence, display how many values were printed.

  3. Ask how many measurements will be entered. Use a for loop to read that many values, count the non-negative and negative readings, and calculate the sum of the non-negative readings. Do not store the readings in a list.


Section E – while Loop Challenges

  1. Implement a while loop that repeatedly asks the user for a positive integer. Ignore negative inputs with a warning. When the user enters 0, stop and print the sum of all positive integers entered.

  2. Create a Collatz-style sequence generator:

    • start from an integer n > 1
    • if n is even, divide it by 2
    • if n is odd, replace it with 3*n + 1 Continue until n becomes 1. Print each value and report how many steps the sequence took.
  3. Build a measurement-summary menu loop without using a list:

    • option 1: ask for a measurement and update a running count and total
    • option 2: display the current count and average (handle the zero-count case)
    • option 0: exit and print the final count and average
    • any other option: print a helpful error message Show a short example interaction to demonstrate the menu.

Section F – Mini Project: Lab Report Tracker

Design a script lab_report_tracker.py to help TAs monitor submissions. - Ask how many lab teams need to be checked. - For each team, ask for the team name and submission status (submitted, draft, or missing). - Count how many teams fall into each category. - After all responses, print a summary and the team names that are still missing. - Lecture 2 constraint: do not use a list. Build one output string for missing team names using concatenation. - Bonus: compute the submission rate as a percentage (submitted teams divided by total teams).

Provide: 1. A short outline (bullet points or flow diagram) of your algorithm.

  1. The core Python code for your solution.

Reflection

  1. Which Lecture 2 topic did you feel most confident about after completing this worksheet?

  2. Which concept still needs practice? How will you continue working on it?

  3. Write one question you want to discuss during the next lab or lecture.