Activities: Week 3¶
You have the following activities to complete:
- Before class Tuesday:
- Read Iteration.
- And try as many of the exercises as you can, thinking about them and noting what’s confusing, what’s hard
- Before class Thursday:
- Read Conditionals
- Read File Input/Output
- Additionally, here are some more introductory videos about concepts we are looking at this week. You may find them very useful; I recommend you watch/listen to them:
- By Sunday at 11:59PM, save answers to the exercises in Problem Set 2:
- Complete each of the problem set problems.
- Submit your Demonstrate Your Understanding 3 assignment.
- Resubmit your last DYU (DYU 2) if you did not get full credit on it.
Problem Set¶
Instructions: Write the code you want to save in the provided boxes, and click save & run for each one. The last code you have saved for each one by the deadline is what will be graded.
Computer programming (often shortened to programming) is a process that leads from an original formulation of a computing problem to executable programs. It involves activities such as analysis, understanding, and generically solving such problems resulting in an algorithm, verification of requirements of the algorithm including its correctness and its resource consumption, implementation (or coding) of the algorithm in a target programming language, testing, debugging, and maintaining the source code, implementation of the build system and management of derived artefacts such as machine code of computer programs. The algorithm is often only represented in human-parseable form and reasoned about using logic. Source code is written in one or more programming languages (such as C++, C#, Java, Python, Smalltalk, JavaScript, etc.). The purpose of programming is to find a sequence of instructions that will automate performing a specific task or solve a given problem. The process of programming thus often requires expertise in many different subjects, including knowledge of the application domain, specialized algorithms and formal logic. Within software engineering, programming (the implementation) is regarded as one phase in a software development process. There is an on-going debate on the extent to which the writing of programs is an art form, a craft, or an engineering discipline. In general, good programming is considered to be the measured application of all three, with the goal of producing an efficient and evolvable software solution (the criteria for "efficient" and "evolvable" vary considerably). The discipline differs from many other technical professions in that programmers, in general, do not need to be licensed or pass any standardized (or governmentally regulated) certification tests in order to call themselves "programmers" or even "software engineers." Because the discipline covers many areas, which may or may not include critical applications, it is debatable whether licensing is required for the profession as a whole. In most cases, the discipline is self-governed by the entities which require the programming, and sometimes very strict environments are defined (e.g. United States Air Force use of AdaCore and security clearance). However, representing oneself as a "professional software engineer" without a license from an accredited institution is illegal in many parts of the world.
several_things
. Then, write another for loop to print out the TYPE of each element of the list called several_things
. To complete this problem you should have written two different for loops, each of which iterates over the list several_things
, but each of those 2 for loops should have a different result.
Write code that uses iteration to print out each element of the list stored in excited_words
, BUT print out each element without its ending punctuation. You should see:
hello
goodbye
wonderful
I love Python
(Hint: remember string slicing?)
original_str
using the accumulation pattern and assign the answer to a variable num_chars_sent
. Do NOT use the len
function to solve the problem (if you use it while you are working on this problem, comment it out afterward!)
about_programming.txt
which has been provided for you in this problem set, and assign the number of lines in the file to the variable file_lines_num
.
The program below doesn’t always work as intended. Try uncommenting different lines setting the initial value of x. Tests will run at the end of your code, and you will get diagnostic error messages.
Fix the code so that it passes the test for each different value of x. So when the first line is uncommented, and when the second line, third line, and fourth line are each uncommented, you should always pass the test.
(HINT: you don’t have to make a big change!)
How many characters are in each element of list lp
? Write code to print the length (number of characters) of each element of the list, on a separate line. (Do not write 8+ lines of code to do this. Use a for loop.)
The output you get should be:
5
13
11
12
3
12
11
6
Use iteration (a for loop).
Write code to count the number of strings in list items
that have the character w
in it. Assign that number to the variable acc_num
.
HINT 1: Use the accumulation pattern!
HINT 2: the in
operator checks whether a substring is present in a string.