zoukankan      html  css  js  c++  java
  • 小球100米反复上下跳;反转字符串单词

    一球从100米高度自由落下,每次落地后反跳回原高度的一半;

    再落下,求它在第10次落地时,共经过多少米?第10次反弹多高?

    def bounce(num):
        #初始高度
        height=100
        #总高度
        total=0
        for i in range(num):
            #第一次下落高度
            total+=height
            #后续的高度变化
            height/=2
        return total,height
    
    
    if __name__ == '__main__':
        t, h = bounce(10)
        print("它在第10次落地时,共经过{}米,第10次反弹高度是{}".format(t, h))
    

    "Let's take LeetCode contest"

    输出: "s'teL ekat edoCteeL tsetnoc"

    def reversalword(word):
        ''':arg 接受的字符串'''
        alist=[]
        #对字符串按照空格进行切片
        for i in word.split(' '):
            #将切片的字符串反转添加到列表中
            alist.append(i[::-1])
            #通过空格连接每一个单词
        return ' '.join(alist)
    
    if __name__ == '__main__':
        word="Let's take LeetCode contest"
        print( reversalword(word))
  • 相关阅读:
    ShiroConfig V2.0
    MyRealm V2.0(注:加上了权限字符串)
    ShiroUtils通用工具包
    ResourcesConfig实现配置资源路径
    MyRealm V1.0
    ShiroConfig V1.0
    MySQL
    Git实战
    scala中函数简单使用记录
    scala中Trait简单使用
  • 原文地址:https://www.cnblogs.com/bronyaa/p/13258156.html
Copyright © 2011-2022 走看看