Skip to content

Commit 9e323df

Browse files
committed
/Users/huangjiabao/bornforthis.cn/docs/1v1/96-Four-dimensional/2022F_TT2.md /Users/huangjiabao/bornforthis.cn/docs/1v1/96-Four-dimensional/CSCA20-Lab1.md /Users/huangjiabao/bornforthis.cn/docs/1v1/96-Four-dimensional/CSCA20-Lab2.md /Users/huangjiabao/bornforthis.cn/docs/1v1/96-Four-dimensional/CSCA20-Lab3.md /Users/huangjiabao/bornforthis.cn/docs/1v1/96-Four-dimensional/CSCA20-Lab4.md /Users/huangjiabao/bornforthis.cn/docs/1v1/96-Four-dimensional/CSCA20-Lab5.md
1 parent fda38e9 commit 9e323df

File tree

3 files changed

+248
-0
lines changed

3 files changed

+248
-0
lines changed
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
---
2+
title: 2022F_TT2
3+
date: 2024-11-22 22:20:46
4+
author: AI悦创
5+
isOriginal: true
6+
icon: blog
7+
sticky: false
8+
star: false
9+
article: true
10+
timeline: true
11+
image: false
12+
navbar: true
13+
sidebarIcon: true
14+
headerDepth: 5
15+
comment: true
16+
lastUpdated: true
17+
editLink: false
18+
backToTop: true
19+
toc: true
20+
watermark: true
21+
---
22+
23+
## Question 1
24+
25+
Completion of this question demonstrates competency in user I/O and competency + mastery in variables
26+
27+
Your job is to write a simple booking app that asks the user to input a day of the week, a starting time, and duration. If the room is free during that time, it will be booked, if the room is not free for some or all of that time, the system will tell the user that the room could not be booked. You may assume that all times begin on a specific hour, and that all bookings are in hour-long increments.
28+
29+
In order to store the bookings, you should create a list of lists of booleans. That is to say, a list of seven elements where each element is a list of 24 boolean (True or False) values representing the booking status for a specific day/hour.
30+
31+
32+
33+
34+
35+
## Question 2
36+
37+
Completion of this question demonstrates competency selection, loops and files, and mastery in selection
38+
39+
Your job is to create a game of MAD-LIBS. Open a file called input.txt and copy the file to output.txt.But you must observe the following rules:
40+
41+
- You should replace all instances of bad words (the only bad words are DARN, HECK, DANG and GOSH[^1]) with the word **CENSORED**
42+
43+
44+
45+
46+
47+
[^1]:if you know of any others, feel free to add them... but I cant imagine a good university student like you knows any worse words
48+
49+
50+
51+
52+
53+
54+
55+
56+
57+
58+
59+
60+
61+
62+
63+
64+
65+
66+
67+
::: details 公众号:AI悦创【二维码】
68+
69+
![](/gzh.jpg)
70+
71+
:::
72+
73+
::: info AI悦创·编程一对一
74+
75+
AI悦创·推出辅导班啦,包括「Python 语言辅导班、C++ 辅导班、java 辅导班、算法/数据结构辅导班、少儿编程、pygame 游戏开发、Web、Linux」,全部都是一对一教学:一对一辅导 + 一对一答疑 + 布置作业 + 项目实践等。当然,还有线下线上摄影课程、Photoshop、Premiere 一对一教学、QQ、微信在线,随时响应!微信:Jiabcdefh
76+
77+
C++ 信息奥赛题解,长期更新!长期招收一对一中小学信息奥赛集训,莆田、厦门地区有机会线下上门,其他地区线上。微信:Jiabcdefh
78+
79+
方法一:[QQ](http://wpa.qq.com/msgrd?v=3&uin=1432803776&site=qq&menu=yes)
80+
81+
方法二:微信:Jiabcdefh
82+
83+
:::
84+
85+
![](/zsxq.jpg)

src/1v1/96-Four-dimensional/CSCA20-Lab3.md

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,87 @@ If you finish early and want to practice more, here are a few things you can try
126126

127127
5. for 循环里面的会重复执行!
128128

129+
6. while 循环语法
130+
131+
```python
132+
while 条件: # 条件为 True 的时候才可以执行
133+
while 循环内的代码
134+
```
135+
136+
```python
137+
while 2 > 1:
138+
print("hello")
139+
```
140+
141+
```python
142+
num = 10
143+
while num > 0:
144+
print(f"hello,{num}")
145+
num -= 1
146+
```
147+
148+
7. while 循环实现 0100
149+
150+
```python
151+
total = 0
152+
n = 0
153+
while n <= 100:
154+
total = total + n
155+
n = n + 1
156+
print(total)
157+
```
158+
159+
8. append() 添加列表元素
160+
161+
```python
162+
lst = [1, 2, 3]
163+
lst.append(5)
164+
print(lst)
165+
lst.append([1, 2, 3])
166+
print(lst)
167+
```
168+
169+
9. 列表删除
170+
171+
```python
172+
lst = [1, 2, 3]
173+
lst.pop()
174+
print(lst)
175+
lst.pop(0)
176+
print(lst)
177+
```
178+
179+
```python
180+
lst = [1, 2, 3, 4]
181+
del lst[0]
182+
print(lst)
183+
del lst[0]
184+
print(lst)
185+
```
186+
187+
```python
188+
lst = [1, 2, 3, 4]
189+
lst.remove(3)
190+
print(lst)
191+
```
192+
193+
10. 列表的修改元素
194+
195+
```python
196+
lst = [1, 2, 3, 4, 5, 6]
197+
lst[0] = 100
198+
print(lst)
199+
```
200+
201+
```python
202+
lst = [1, 2, 3, 4, 5, 6]
203+
for i in range(len(lst)):
204+
lst[i] = lst[i] ** 2
205+
print(lst)
206+
```
207+
208+
209+
129210

130211

131212

@@ -188,6 +269,73 @@ average_time = 0
188269
print("Average for qualifying runners: " + str(average_time))
189270
```
190271

272+
@tab Code
273+
274+
```python
275+
# This will be our continue flag... if it's set to 'N', we're done.
276+
# If it's set to 'Y' (or anything else), we add more runners.
277+
cont = "Y"
278+
279+
# Lists to hold our runners and their times, so runners[n] will be the name of
280+
# the n'th place finisher and times[n] will be their time (in minutes).
281+
runners = []
282+
times = []
283+
284+
# Loop until the user says they're out of runners to process.
285+
while cont != "N":
286+
# Get the name and time of the next runner.
287+
runner_name = input("Please enter the name of the next runner: ")
288+
runner_time = float(input("Please enter the runner's time: "))
289+
290+
# Add the name and time to their respective lists.
291+
runners.append(runner_name)
292+
times.append(runner_time)
293+
294+
# Ask if the user is done.
295+
cont = input("Any more runners to add? (Y/N): ")
296+
297+
# Calculate the average time of all runners.
298+
total = 0
299+
num_runners = 0
300+
for next_time in times:
301+
total += next_time
302+
num_runners += 1
303+
print("Average time of all runners: " + str(total / num_runners))
304+
305+
# Calculate the average time and list of qualified runners.
306+
total = 0
307+
max_num_runners = int(input("Enter the number of runners who qualified: "))
308+
309+
# Loop over the positions (0, 1, 2, etc.) to access both lists (names and times).
310+
for runner_num in range(0, max_num_runners):
311+
total += times[runner_num]
312+
print(runners[runner_num] + " qualified")
313+
print("Average time for qualified runners: " + str(total / max_num_runners))
314+
315+
# Handle cutoff time to qualify.
316+
cutoff_time = float(input("Enter cutoff time to qualify: "))
317+
total = 0
318+
319+
# We need to keep track of our own position and values this time.
320+
num_runners = 0
321+
next_runner = runners[0]
322+
next_time = times[0]
323+
324+
# Keep looping until we hit a time that doesn't qualify.
325+
while next_time < cutoff_time:
326+
print(next_runner + " qualified")
327+
total += next_time
328+
329+
# Update the counter and fetch the next runner.
330+
num_runners += 1
331+
if num_runners >= len(runners): # Ensure we don't exceed the list size.
332+
break
333+
next_runner = runners[num_runners]
334+
next_time = times[num_runners]
335+
```
336+
337+
338+
191339
:::
192340

193341

src/1v1/96-Four-dimensional/CSCA20-Lab5.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,21 @@ You’ll need to build a menu that prompts the user for their phone number, dono
6666

6767
## 9. Hints
6868

69+
Here are a few hints that might help you with this assignment:
70+
71+
- Work on one function at a time. Don’t waste mental resources thinking about how you’re going to use the character matching function while you’re implementing it, and likewise, when you’re implementing it, just trust that the function itself will work.
72+
- Test each function before you move on. It can get really complicated if you have a bug in your function that you don’t realize until it’s being called by another function.
73+
- Document your functions thoroughly, and read the provided documentation. This goes back to separating algorithm from implementation: focus on the algorithm with the documenta-tion, then you can worry about implementation separately.
74+
- There are a few assumptions you can make that will simplify your life. For example: Since the documentation for matches_string says the strings must be of the same length, inside the function you can just take that for granted. Then worrying about different length strings becomes a separate (and easily solved) problem.
75+
76+
## 10. Extra Practice
77+
78+
Here are some ideas of things you can do if you’re finished early or just want more to do:
79+
80+
- Adding extra templates is fairly easy, but what about adding extra template types? For example, what about adding a a symbol that works for only upper case letters? Or what about one that works for anything **except** spaces?
81+
- For a real challenge, try making `#` match any string of numbers and `&` match any string of letters. So phone numbers would be `(#)#-#`, which would match (123)456-7890 (but would also match (12345)6-123456789. (As a hint for this one, make a function that doesn’t return `True` or `False` if a string matches a template, but the number of characters that it matches before failing)
82+
- If you like the fun of the templates part, you can learn more about these sort of tools: we call them regular expressions, and they can actually be very powerful. We will see these more later in the term, but you can play around with them now: [https://www.w3schools.com/python/python_regex.asp](https://www.w3schools.com/python/python_regex.asp)
83+
6984

7085

7186

0 commit comments

Comments
 (0)