Day2--#100Days of python coding

  • Mathematical operation in python
    string can't be converted to int need to be float() first
  • Number manupulation and f string in python
  • Round the number 
    use round( )
    round(8/3,3)
    round to different desimal places
  • Use floor divison---
    8//3
    type(8//3)
    // to be an integer
    / to be a float
  • f string 
score=0
print("your score is "+str(score))

#f-String

in front of the double quote / single quoteuse print() below to check your code!

  • 2.0但我仍然要两位数👇

Using str.format()'s syntax to display answer with two decimal places (without altering the underlying value of answer):

def printC(answer):
    print("\nYour Celsius value is {:0.2f}ºC.\n".format(answer))

Where:

  • : introduces the format spec
  • 0 enables sign-aware zero-padding for numeric types
  • .2 sets the  precision to 2
  • f displays the number as a fixed-point number
  • Condition statement
    water_level = 50
    if water_level > 80:
      print("Drain water")
    else:
      print("Continue")

    Comparison Operators

  • == check if the value on the left is equal to the right

  • = means that you're assigning this value(right) to this valuable(left)

  • !=

  • Modulo Operation
     
7%2
1
  • Nested if /else
if condition:
   if another condition :
      do this
   else:
      do this
else :
   do this
  • elif statement
  • Multiple if statements
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值