Skip to content

Commit 44f2648

Browse files
authored
Update quiz1.rs
1 parent 0776a7e commit 44f2648

File tree

1 file changed

+6
-21
lines changed

1 file changed

+6
-21
lines changed

exercises/quiz1.rs

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,15 @@
1-
// quiz1.rs
2-
//
3-
// This is a quiz for the following sections:
4-
// - Variables
5-
// - Functions
6-
// - If
7-
//
8-
// Mary is buying apples. The price of an apple is calculated as follows:
9-
// - An apple costs 2 rustbucks.
10-
// - If Mary buys more than 40 apples, each apple only costs 1 rustbuck!
11-
// Write a function that calculates the price of an order of apples given the
12-
// quantity bought. No hints this time!
13-
//
14-
// No hints this time ;)
15-
16-
17-
// Put your function here!
1+
// 计算苹果总价的函数:
2+
// - 购买数量 ≤40:每个2 rustbucks
3+
// - 购买数量 >40:每个1 rustbuck
184
fn calculate_price_of_apples(number: i32) -> i32 {
19-
205
if number > 40 {
21-
number
6+
number * 1 // 超过40个,单价1 rustbuck
227
} else {
23-
number * 2
8+
number * 2 // 40个及以下,单价2 rustbucks
249
}
2510
}
2611

27-
// Don't modify this function!
12+
// 无需修改的测试函数
2813
#[test]
2914
fn verify_test() {
3015
let price1 = calculate_price_of_apples(35);

0 commit comments

Comments
 (0)