File tree Expand file tree Collapse file tree 1 file changed +6
-21
lines changed
Expand file tree Collapse file tree 1 file changed +6
-21
lines changed Original file line number Diff line number Diff line change 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
184fn 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]
2914fn verify_test ( ) {
3015 let price1 = calculate_price_of_apples ( 35 ) ;
You can’t perform that action at this time.
0 commit comments