计算机专外Week5-Exercises
来源:互联网 发布:游戏同步器软件 编辑:程序博客网 时间:2024/05/16 05:18
Week 5 > Table startsWith endsWith Exercises > Problems
Q1: Write code to print all the rows where the name starts with “X”.
table = new SimpleTable("baby-2010.csv");for (row: table) { // your code here if(row.getField("name").startsWith("X")){ print(row); }}
Q2: Write code to print all the rows where the name starts with “Xz”.
table = new SimpleTable("baby-2010.csv");for (row: table) { // your code here if(row.getField("name").startsWith("Xz")){ print(row); }}
Q3: Write code to print all the rows where the name ends with “x”.
table = new SimpleTable("baby-2010.csv");for (row: table) { // your code here if(row.getField("name").endsWith("x")){ print(row); }}
Week 5 > Table Boolean Logic Exercises > Problems
Q1: Write code to print all the rows where the name starts with “X” or the name starts with “Y”. Suggestion: when you have code running, look carefully at the output. Does the output look reasonable? For this problem for example, do you see a mix of names starting with either “X” or “Y”? It’s nice to get in the habit of thinking critically about your code and its output.
table = new SimpleTable("baby-2010.csv");for (row: table) { // your code here if(row.getField("name").startsWith("X")||(row.getField("name").startsWith("Y"))){ print(row) }}
Q2: Write code to print all the rows where the name starts with “B” and the name ends with “a”. As with the previous exercise, check your output by eye to see if it looks reasonable.
table = new SimpleTable("baby-2010.csv");for (row: table) { // your code here if (row.getField("name").startsWith("B") && row.getField("name").endsWith("a")) { print(row); }}
Q3: Write code to print all the rows where the name ends with “i” and the gender is “boy”. Reminder of “boy” test: row.getField(“gender”) == “boy”
table = new SimpleTable("baby-2010.csv");for (row: table) { // your code here if (row.getField("name").endsWith("i") && row.getField("gender") == "boy") { print(row); }}
Week 5 > Table Counting Exercises > Problems
Q1: Write code to count and print number of names starting with the letter “O”. The last line printed should look like the “count: 23” example above (of course the answer is not 23). You can print out rows or other things in the loop too if you like, so long as the “count: 23” line appears at the end.
table = new SimpleTable("baby-2010.csv");count = 0;for (row: table) { // your code here if (row.getField("name").startsWith("O")) { print(row); count = count + 1; // increases the value in count by 1 }}print("count:", count);
Q2: Write code to count and print number of girl names starting with “T”. The last line printed should follow the “count: 23” format as usual.
table = new SimpleTable("baby-2010.csv");count = 0;for (row: table) { // your code here if (row.getField("name").startsWith("T")&& (row.getField("gender")=="girl")){ print(row); count = count + 1; }}print("count:", count);
Q3: Write code to count and print number of boy names ending with “d”. The last line printed should follow the “count: 23” format as usual.
table = new SimpleTable("baby-2010.csv");count = 0;for (row: table) { // your code here if (row.getField("name").endsWith("d")&& (row.getField("gender")=="boy")){ print(row); count = count + 1; }}print("count:", count);
Week 5 > Table Counting Multiple Exercises > Problems
Q1: Do more baby names start with “A” or “B”? Write code to count and print those two counts (“A” count, then “B” count).
table = new SimpleTable("baby-2010.csv");count1 = 0;count2 = 0;for (row: table) { // your code here if (row.getField("name").startsWith("A")){ print(row); count1 = count1 + 1; } if (row.getField("name").startsWith("B")){ print(row); count2 = count2 + 1; }}print("Acount:", count1);print("Bcount:", count2);
Q2: Now we’ll look at the survey data. How many people identified “red” or “blue” as their favorite color? The appropriate field in the survey is “color”. Write code to count and print those two cases (“red” count, then “blue” count).
table = new SimpleTable("survey-2012.csv");table.convertToLowerCase();count1 = 0;count2 = 0;for (row: table) { // your code here if (row.getField("color")=="red"){ print(row); count1 = count1 + 1; } if (row.getField("color")=="blue"){ print(row); count2 = count2 + 1; }}print("Red count:", count1);print("Blue count:", count2);
Q3: Instead of looking at the whole survey, let’s look only at the people who identified “coke” as their favorite soda (not “diet coke”, just “coke”). How many of them (“coke” rows) identified “red” or “blue” as their favorite color? The appropriate fields in the survey are “soda” and “color”. Write code to count and print those two cases (“red” count, then “blue” count).
table = new SimpleTable("survey-2012.csv");table.convertToLowerCase();count1 = 0;count2 = 0;for (row: table) { // your code here if(row.getField("soda")=="coke"){ if (row.getField("color")=="red"){ print(row); count1 = count1 + 1; } if (row.getField("color")=="blue"){ print(row); count2 = count2 + 1; } }}print("Red count:", count1);print("Blue count:", count2);
Week 5 > Analog and Digital Exercises > Problems
Q1: Suppose we have two musical notes, X and Y, and note X is higher than note Y. Which one of the following must be true.
Note X has more cycles per second than note Y. - correct
Note Y has more cycles per second than note X.
Note X has a higher amplitude than note Y.
Note Y has a higher amplitude than note X.
Q2: Clearly it is possible to be in a room and hear two distinct sounds at the same time. Which one of the following describes how this works.
The sound signals mix in the air, forming a sum signal. The ear takes in this sum and recovers the original signals. - correct
One sound goes in one ear, while the other sound goes in the other ear.
The higher sound goes in the ear, the lower sound comes in through the foot.
Higher sounds proceed with vertically polarized waves, while lower sounds proceed with horizontally polarized waves. Thus the two waves enter the ear without interference.
Q3: Select any of the following which are examples of an analog system.
Suppose we have two cans connected with string. Speak into one tin can. The can vibrates a string, which vibrates the can at the other end. - correct
On vinyl music records there are tiny up and down movements cut into the plastic to represent the up and down movements of the sound on the record. - correct
Visualize an 18th century pirate sailing ship. Visualize the big ship’s wheel. The wheel is connected through a series of ropes and pulleys to the big vertical rudder at the back of the ship. Turning the wheel a little moves the rudder a little. Turning the wheel a lot moves the rudder a lot.- correct
- 计算机专外Week5-Exercises
- 计算机专外-Week1 exercises
- 计算机专外Week2-Exercises
- 计算机专外Week4-Exercises
- 计算机专外Week6-Exercises
- week5
- Exercises
- POMM-week5
- No5.week5
- Leetcode Week5
- leetcode week5
- LeetCode Week5
- Algorithm-week5
- 练习(Exercises)
- training exercises
- Exercises 2.2
- Exercises 3.3
- Exercises 4.1
- Unix网络编程:从入门到放弃——一个简单的时间获取程序
- css link @import
- Spring 中配置log4j日志功能
- [线段树] [BZOJ4499] 线性函数
- Python爬虫之基础篇
- 计算机专外Week5-Exercises
- Vuforia自学笔记(一)生成识别图的unity开发包
- Android Dialog用法
- Google Font、Icon CDN加速代理
- 【Tensorflow】Windows下基于Anaconda的Tensorflow环境配置
- 2843 拯救炜哥 (bfs)
- js正则表达式报Nothing to repeat
- 单变元模线性方程
- HDU 6020 MG loves apple