ch_chengji<-function(x){
if(x>95){
return("这个学生语文成绩不错啊,成绩评为:A++")
}else if(x>90&&x<=95){
return("这个学生语文成绩挺好的,成绩评为:A+")
}else if(x>80&&x<=90){
return("这个学生语文成绩还行,成绩评为:B++")
}else if(x>70&&x<=80){
return("这个学生语文成绩也行,成绩评为:B+")
}else if(x>60&&x<=79){
return("这个学生语文成绩刚好合格哦,成绩评为:C")
}else{
return("看来你的成绩实在是不行哦,还得加油")
}
}
ch_chengji(100)
ch_chengji(96)
ch_chengji(90)
ch_chengji(80)
ch_chengji(70)
ch_chengji(61)
ch_chengji(50)say_sign<-function(x){
if(x>0){
cat ("the number is greater than 0")
}else if(x<0){
cat ("the number is less than 0")
}else{
cat ("the number is 0")
}
}
say_sign(1)
say_sign(-3)
say_sign(0)
grade<-function(x){
if(x>=90){
return("the student very very youxiu")
}else if(x>70&&x<90){
return("the student just soso")
}else{
return("这个成绩可是没有合格哦")
}
}
grade(1)
grade(55)
grade(66)
grade(88)
grade(98)
grade<-function(score){
if(score>=90){
return("A")
}else if(score>=80){
return("B")
}else if(score>=70){
return("C")
}else if(score>=60){
return("D")
}else{
return("F")
}
}
grade(23)
grade(67)
grade(77)
grade(88)
grade(90)
c(grade(55),grade(66),grade(77),grade(88),grade(99))
grade2<-function(score){
if(score>=60){
return("C")
}else if(score>=70){
return("B")
}else if(score>=80){
return("A")
}else{
return("AA")
}
}
grade2(78)
grade2(88)
grade2(55)
grade2<-function(x){
if(x>90&&x<=100){
return("A")
}else if(x>80&&x<=90){
return("B")
}else if(x>70&&x<=80){
return("C")
}else{
return("D")
}
}
grade2(78)
grade2(90)
grade2(98)
p<-c(grade2(78),grade2(90),grade2(90))
check_positive<-function(x){
return(if(x>0){
666
})
}
check_positive(1)
check_positive<-function(x){
return(if(x>0)88)
}
check_positive(3)
check_positive<-function(x){
if(x>0)88
}
check_positive(7)
check_positive<-function(x){
if(x>0) 1 else if(x<0) -1 else 0
}
check_positive(6)
check_positive(-6)
check_positive(0)
check_positive<-function(x){
if(x>0)6
}
check_positive(8)
check_positive<-function(x){
if(x>90)"A" else if(x>80)"B" else if(x>70)"C" else"D"
}
check_positive(87)
check_positive(98)
check_positive(78)
check_positive(68)
grade<-function(x){
if(x>90)"这个学生成绩优秀" else if(x>80)"这个学生成绩还不错" else if(x>70)"这个学生成绩合格啦" else "这个学生成绩不合格"
}
grade(90)
grade(80)
grade(70)
grade(60)
grade(55)
say_grade<-function(name,score){
grade<-if(score>=90)"A"
else if(score>=80)"B"
else if(score>=70)"C"
else if(score>=60)"D"
else "E"
cat ("the gradde of", name,"is", grade)#需要写入
}
say_grade("zhangsan",90)
say_sign("zhangsan",98)
say_sign("lisi",88)
say_sign("wangmazi",66)
say_sign("yoyo",55)
say_grade<-function(name,score){
if(score>=90) grade<-"A"
else if(score>=80) grade<-"B"
else if(score>=75.5) grade<-"C"
else if(score>=70) grade<-"D"
else if(score>=60) grade<-"E"
else if(score>=50) grade<-"F"
else grade<-"G"
cat ("what a pity!\n")
cat ("the",name,"chengji is",grade)
}
say_grade("wangmazi",67)
say_grade("zhangsan",88)
say_grade<-function(name,score){
if(score>=90){
grade<-"C"
}else if(score>=80){
grade<-"B"
}else if(score>=70){
grade<-"C"
}else{
grade<-"D"
}
cat("the",name,"chengji is",grade)
}
say_grade("yoyo",78)
say_grade("kangkang",8768)
ifelse(c(TRUE,FALSE,FALSE),c(1,2,3),c(4,5,6))
ifelse(c("FALSE"),c("1"),c("8"))
switch(1,"x","y")
switch(2,"x","y")
switch(3."x","y")
if(TRUE)c(1,2)else c(2,3)
if(TRUE)c(1,2)else c(5,6)
if(FALSE)c(1,2)else c(5,8)
ifelse(c(TRUE,FALSE),c(1,2),c("a","b"))
ifelse(c(TRUE,FALSE),c(5,6),c("a","2"))
switch(1,"x","y")
switch(3,"x","y","z")
switch(1.5,"x","y","z","m","n")
switch(4,"x","y","z","m","n")
switch("a",a=1,b=2)
switch("b",a=1,b=2,c=3)
tem<-function(x){
if(x>60){
return("ye,zheige wendu taigaol")
}else if(x>30&&x<=60){
return("ai ,zhgei wendu gangganghaoba")
}else if("x>20&&x<=30"){
return("zheige wendu ba haixing")
}else{
return("oh ,zheige wendu taidil ,wo shoubula")
}
}
tem(80)
tem(0)
tem(32)
网友评论