VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > temp > python入门教程 >
  • python基础学习2

今天学习了条件判断语句

# -*- coding = utf-8 -*-                                   
# @Time : 2022/8/26 10:25                                  
# @Author : 鹤城                                             
# @File : demo3.py                                         
# @Software : PyCharm                                      
                                                           
#条件判断语句                                                    
'''                                                        
if True:                                                   
    print("Answer")                                        
    print("True")                                          
else:                                                      
    print("Answer")                                        
    print("False")                                         
print("end")                                               
'''                                                        
                                                           
#else和elif一起使用                                             
'''                                                        
score = 68                                                 
if score >=90 and score <=100:                             
    print("A")                                             
elif score >=80 and score < 90:                            
    print("B")                                             
elif score >=70 and score < 80:                            
    print("C")                                             
elif score >=60 and score < 70:                            
    print("D")                                             
elif score >=0 :#and score < 60:                           
    print("E")                                             
'''                                                        
                                                           
#条件语句的嵌套                                                   
'''                                                        
sex = 0                                                    
duixiang = 0                                               
if sex == 1:                                               
    print("男")                                             
    if duixiang == 1:                                      
        print("有对象")                                       
    else:                                                  
        print("单身")                                        
else:                                                      
    print("女")                                             
    if duixiang == 1:                                      
        print("有对象")                                       
    else:                                                  
        print("单身")                                        
'''                                                        
                                                           
# 随机数                                                      
import random                #引入随机库                        
x = random.randint(0,2)      #随机生成【0,2】之间的整数               
print(x)                                                   

还有循环控制语句

#循环控制语句

# for循环
# for i in range(5):
#     print(i)

# for i in range(0,10,2):    #从零开始,到十结束,每次加二,不包括十
#     print(i)

# for a in range(-10,-100,-30):
#     print(a)

# name = "chengdu"
# for x in name:
#     print(x,end="\t")

# a = ["aa","bb","cc","dd"]
# for i in range(len(a)):
#     print(i,a[i])

#while循环
# i = 0
# while i < 5 :
#     print("这是第%d次循环"%(i+1))
#     print("i=%d"%i)
#     i += 1                                   #里面要有增长变量

#1-100求和
# sum = 0
# x = 1
# n= 100
# while x <= n:
#     sum += x
#     x += 1
# print("1到%d的和为%d"%(n,sum))

#whileelse连用
count = 0
while count < 5:
    print(count,"小于5")
    count += 1
else:
    print(count,"大于或等于5")
 


相关教程