8: Remix
Source: https://cscircles.cemc.uwaterloo.ca/8-remix/ Parent: https://cscircles.cemc.uwaterloo.ca/
This lesson consists of several exercises that combine the different skills you learned in the previous lessons.
Coding Exercise: Python Adder
Write a program that takes a single input line of the form «number1»+«number2», where both of these represent positive integers, and outputs the sum of the two numbers. For example on input 5+12 the output should be 17. Hint 1Hint 2
You need to create an account and log in to ask a question.
S = input()
delete this comment and enter your code here
You may enter input for the program in the box below.
More actions... History Reset code to default Help
Coding Exercise: Substring Counting
As mentioned in lesson 7A, a substring is any consecutive sequence of characters inside another string. The same substring may occur several times inside the same string: for example "assesses" has the substring "sses" 2 times, and "trans-Panamanian banana" has the substring "an" 6 times. Write a program that takes two lines of input, we call the first needle and the second haystack. Print the number of times that needle occurs as a substring of haystack. Hint
You need to create an account and log in to ask a question.
delete this comment and enter your code here
You may enter input for the program in the box below.
More actions... History Help
In the following question, once you get it correct we'll show you a graphical representation of the output using * graphics.
Coding Exercise: Watch the Pendulum
In physics, for a pendulum with length L and initial angle A, its horizontal displacement X(T) at time T is given by the formula
X(T) = L × cos(A × cos(T × √9.8/L)) - L × cos(A)
Write a program which takes two lines of input; the first line is L and the second line is A. The output should be ten lines, giving the values of X(0), X(1), X(2), ..., X(9). For example, if the first line of input is 53.1 and the second line of input is 0.8, then the first line of output is 0.0 and the second line of output is 53.1*cos(0.8*cos(1*√9.8/53.1)) - 53.1*cos(0.8) ~ 2.6689.
You need to create an account and log in to ask a question.
import statement goes here
L = float(input()) A = float(input())
delete this comment and enter your code here
You may enter input for the program in the box below.
More actions... History Reset code to default Help
Coding Exercise: Centering Text
For this program, the first line of input is an integer width. Then, there are some lines of text; the line "END" indicates the end of the text. For each line of text, you need to print out a centered version of it, by adding periods .. to the left and right, so that the total length of each line of text is width. (All input lines will have length at most width.) Centering means that the number of periods added to the left and added to the right should be equal if possible; if needed we allow one more period on the left than the right. For example, for input
13\
Text\
in\
the\
middle!\
END
the correct output would be
.....Text....\
......in.....\
.....the.....\
...middle!...
Hint
You need to create an account and log in to ask a question.
width = int(input())
delete this comment and enter your code here
You may enter input for the program in the box below.
More actions... History Reset code to default Help