zoukankan      html  css  js  c++  java
  • 习题练习1

    习题1

      三角形三条边长度分别为3、7、9,计算这个三角形的三角度数(用弧度制表示)

    >>> import math
    >>> a = 3
    >>> b = 7
    >>> c = 9
    >>> cosC = (a**2 + b**2 - c**2) / c**2
    >>> C = math.acos(cosC)
    >>> print(C)
    1.8587081466565707

    习题2

      对于字符串: 'you need python'

      - 分别得到三个单词

      - 按照从左向右的顺序,各一个字符取一个

      - 按照从右向左的顺序,各一个字符取一个

      - 将字符串反序

    >>> s = 'you need python'
    >>> s.split()
    ['you', 'need', 'python']
    >>> s[::2]
    'yune yhn'
    >>> s[::-2]
    'nhy enuy'
    >>> s[::-1]
    'nohtyp deen uoy'

    习题3

      字符串'hello',字母h的左侧和o的右侧都有空格,使用字符串的方法去除空格

      将字符串"you need python"中的空格用"*"替代

    >>> h = '  hello  '
    >>> h
    '  hello  '
    >>> h.strip()
    'hello'

    >>> s = 'you need python' >>> '*'.join(s.split()) 'you*need*python'

    习题4

      编写程序,实现以下操作:

      - 通过键盘输入数字,作为圆的半径

      - 计算圆的周长和面积,并分别打印显示出来,结果保留两位小数

    import math
    
    n = input('please input a number:')
    n = float(n)
    
    circle = 2 * math.pi * n
    area = math.pi * n**2
    
    print('the circle is:', round(circle, 2))
    print('the area is:', round(area, 2))

    please input a number:5
    the circle is: 31.42
    the area is: 78.54

    习题5

      编写程序,实现如下功能

      - 询问用户姓名和年龄

      - 计算10年之后的年龄

      - 打印出用户的姓名,极其现在和10年后的年龄

    name = input('your name:')
    age = input('your age:')
    
    after_ten = int(age) + 10
    
    print("-"*10)
    print("your name is {0}. 
    you ate {1} years, now. 
    After the years, you are {2}".format(name, age, after_ten))

    your name:zhangsan
    your age:30
    ----------
    your name is zhangsan.
    you ate 30 years, now.
    After the years, you are 40







  • 相关阅读:
    归并排序(Merge Sort)
    AtCoder AGC035D Add and Remove (状压DP)
    AtCoder AGC034D Manhattan Max Matching (费用流)
    AtCoder AGC033F Adding Edges (图论)
    AtCoder AGC031F Walk on Graph (图论、数论)
    AtCoder AGC031E Snuke the Phantom Thief (费用流)
    AtCoder AGC029F Construction of a Tree (二分图匹配)
    AtCoder AGC029E Wandering TKHS
    AtCoder AGC039F Min Product Sum (容斥原理、组合计数、DP)
    AtCoder AGC035E Develop (DP、图论、计数)
  • 原文地址:https://www.cnblogs.com/zhaop8078/p/11824505.html
Copyright © 2011-2022 走看看