大家在学习编程语言的时候,是不是都会觉得很枯燥呢?所以今天我们换一个姿势,用优雅的方式表达出来,会不会增加大家对学习编程语言的兴趣呢?反正我一直在探寻,不知你是否也正在探寻。
编程要求:如何用R语言实现食堂饭卡刷卡扣费
1,目标具体化

2,把任务分解拆分到每一个动作


3,把动作变为R语言

,


4,语句编写完成进行效验

5,容易出错的地方
错误:新手经常忘记加载包

错误:中英文、全角与半角的转换

源代码
#定义函数
#功能:刷卡吃饭
everday <- function(eat,wallet){
#循环语句
for(i in eat)
{
eatNumber <-str_c("共吃第几次饭:",i,sep = "")
wallet<-wallet-5*eat
print(eatNumber)
}
#条件判定语句
if(wallet>0){print("钱包还有钱,放心吃")
}else{
print("钱包没有钱了,去银行吧")}
}
#吃了几次饭
everday(20,100)
如何换一个优雅的姿势进行学习!!


网友评论