Python0508_数据特性与if语句

  • Python中数据特性归类
>>> #不可变类型	
>>> int ,str ,bool ,turple
>>> #可变类型	
>>> list, set, dict
>>> #有序	
>>> str, list ,turple
>>> #无序	
>>> set, dict, int, bool
>>> #可迭代	
>>> str ,list, set, turle, dict
>>> #不可迭代	
>>> int ,bool
  • if,elif,else的运用
x = input("请输入你的成绩:") #input your score
try:
   x = float(x)
except: ValueError
if type(x)!=type(0.0):
   print("输入有误!")
else:
   s = x/10
   if s > 9:
      print("你的成绩为优秀!")
   elif s > 8:
      print("你的成绩为良好!")
   elif s > 7:
      print("你的成绩为中等!")
   elif s > 6:
      print("你的成绩为合格!")
   else :
      print("你的成绩为差!")

if elif else
s>9 7>s>6,>s>7,9>s>8 \
90分以上 60到90分 60分一下
  • 等价于
x = input("请输入你的成绩:") #input your score
try:
   x = float(x)
except: ValueError
if type(x)!=type(0.0):
   print("输入有误!")
else:
   s = x/10
   if s > 9:
      print("你的成绩为优秀!")
   if 9 >= s > 8:
      print("你的成绩为良好!")
   if 8 >= s > 7:
      print("你的成绩为中等!")
   if 7 >= s > 6:
      print("你的成绩为合格!")
   if s < 6 :
      print("你的成绩为差!")
  • 等价于
x = input("请输入你的成绩:") #input your score
try:
   x = float(x)
except: ValueError
if type(x)!=type(0.0):
   print("输入有误!")
else:
   s = x/10
   if s >= 0:
      if  s >= 6:
         if s >= 7:
            if s >= 8:
               if s >= 9:
                  if s <= 10 :
                     print("你的成绩为优秀!")
               else:
                  print("你的成绩为良好!")
            else:
               print("你的成绩为中等!")
         else:
             print("你的成绩为合格!")
      else:
         print("你的成绩为差!")
发布了35 篇原创文章 · 获赞 30 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/weixin_43792401/article/details/89977059