Automate the boring stuff with Python: Comma Code

前端 未结 29 964
深忆病人
深忆病人 2021-02-03 16:17

Currently working my way through this beginners book and have completed one of the practice projects \'Comma Code\' which asks the user to construct a program which:

29条回答
  •  别跟我提以往
    2021-02-03 16:44

    I'm new to python, there might be other easier solutions but here's mine

        spam = ["cats","dogs","cows","apes"]
        def commaCode(list):
            list[-1] =  "and " + list[-1]
            print(", ".join(list))
    
    
        commaCode(spam)
    

提交回复
热议问题