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.
- Download the answer template EE1021_L02_Homework_Template.py from the CATS assignment.
- Rename it to
EE1021_L02_<student number>.py. Example:EE1021_L02_2500001234.py. - 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. - Under each problem, paste the output of one test run as comments (
#). For input problems, include what you typed. - Write your explanations and the Reflection answers as comments too.
- Run the file once for every problem you answered. It must run without errors.
- 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
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
printstatement(s) you used and copy the output.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.
Turn
phrase = "Prototype Verified Successfully"into the acronymPVSusing 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
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.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.
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
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.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) andpeople. Display:Invalid inputif either value is negativeSafeifload_kg <= 300andpeople <= 4Cautionifload_kg <= 400andpeople <= 5Over limitotherwise Test the program with at least one boundary value (such as300,301,400, or401), and withload_kg = 200andpeople = 6. Briefly explain how yourif/elif/elsestructure guarantees that only one message appears.
Ask for a month number (1–12) and print the corresponding season in English:
Winter,Spring,Summer, orAutumn. Handle invalid inputs (e.g., 0 or 15) with a helpful message.
Section D – for Loop Practice
Use a
forloop andrangeto 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.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.
Ask how many measurements will be entered. Use a
forloop 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
Implement a
whileloop that repeatedly asks the user for a positive integer. Ignore negative inputs with a warning. When the user enters0, stop and print the sum of all positive integers entered.Create a Collatz-style sequence generator:
- start from an integer
n > 1 - if
nis even, divide it by 2 - if
nis odd, replace it with3*n + 1Continue untilnbecomes 1. Print each value and report how many steps the sequence took.
- start from an integer
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.
- option
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.
- The core Python code for your solution.
Reflection
Which Lecture 2 topic did you feel most confident about after completing this worksheet?
Which concept still needs practice? How will you continue working on it?
Write one question you want to discuss during the next lab or lecture.