我现在正在研究Swift代码,为了好玩,我有个问题。
代码是
func getMilk(bottles: Int) {
var cost = bottles * 1.5
print("Milk cost is $\(cost)")
}
getMilk(bottles: 4)发布于 2022-01-31 09:12:10
func getMilk(numberOfBottles: Int,
bottleVolume: Float) -> Float {
var cost = Float(numberOfBottles) * bottleVolume
return cost
}
print("Milk func return: \(getMilk(bottles: 5, bottleVolume: 1.5))")这个例子将返回在瓶子中的牛奶总量,给出瓶子的数量和每个瓶子的容量。
很棒的决定学习Swift的工作!
请记住,不要在代码中使用神奇的数字。
https://stackoverflow.com/questions/70923216
复制相似问题