full-speed-python习题解答(一)

本文深入探讨了Python中各种数学运算的使用方法,包括基本的算术运算、求平均值、计算球体体积以及判断数的奇偶性。同时,通过具体的代码示例展示了如何在Python中进行这些计算,并提供了在Python REPL环境中测试特定条件表达式的技巧。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

项目地址:网页地址

full-speed-python书籍地址:https://github.com/joaoventura/full-speed-python
3.1 Exercises with numbers


  • 1.Try the following mathematical calculations and guess what is happening: (3/2),(3//2), (3%2), (3**2).

      print(3/2)
      print(3//2)
      print(3%2)
      print(3**2)
    
  • 1.5
    1
    1
    9
    

  • 2.Calculate the average of the following sequences of numbers: (2, 4), (4, 8, 9), (12,14/6, 15)

      a = [2,4]+[4,8,9]+[12,14/6,15]
      sum = 0
      for each in a:
          sum+=each
      ave = sum/len(a)
      ave
    
  • 7.041666666666667
    

  • 3.The volume of a sphere is given by 4/3πr^3. Calculate the volume of a sphere of radius 5. Suggestion: create a variable named “pi” with the value of 3.1415

      pi = 3.1415
      r = 5
      volume =4/3*(pi*pow(r,3))
      volume
    
  • 523.5833333333333
    

  • 4.Use the module operator (%) to check which of the following numbers is even or odd: (1, 5, 20, 60/7).

      can = [1,5,20,60/7]
      for each in can:
          if each % 2 == 0:
              print(each,' is even')
          else:
              print(each,' is odd')
    
  • 1  is odd
    5  is odd
    20  is even
    8.571428571428571  is odd
    

  • 5.Find some values for x and y such that x < 1/3 < y returns “True” on the Python REPL. Suggestion: try 0 < 1/3 < 1 on the REPL.

      0<1/3<1
    
  • True
    

参考链接:网页链接

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值