Python学习之路-第一天

时间:2022-09-01 00:32:07

在学习python之前一直纠结要不要学,之前会一点java,语言在精,不再多。学习python会不会是在浪费时间,但网上一句“人生苦短,我用python”,又激起了我学习python的兴趣,下面是我学习python第一天的内容,以博客文章的形式记录学习过程中的 点点滴滴.........

1.开始写python代码前在python 2.xx中必写的两句话,python 3.xx不用

#!usr/bin/env python

#_*_ conding:utf-8 _*_

2.变量---保存存储值的内存位置

(1)声明变量

num = 1

变量名:num

变量值:1

=:是赋值的意思,不是相等

注:python是动态语言,不必考虑数据类型,查看数据类型用type,例如:

print(type(num))

3.if,if...elif循环

guess_num_game ==66

guess_num = int(input("guess_num:"))
if guess_num == guess_num_game:
print("恭喜你,才对了")
break
elif guess_num>guess_num_gane:
print("再小一点")
else:
print("再大一点")
3.while
guess_num_game ==66
count = 0while count < 3: 
guess_num = int(input("guess_num:"))
if guess_num == guess_num_game:    print("恭喜你,才对了")    breakelif guess_num>guess_num_gane:    print("再小一点")else:    print("再大一点")
count +=1else: print("不好意思,您的机会已经用完,请下次再猜")
4.for循环
guess_num_game ==66
for i in range(3):    guess_num = int(input("guess_num:")) 
if guess_num == guess_num_game:
print("恭喜你,才对了")
break
elif guess_num>guess_num_gane:
print("再小一点")
else:
print("再大一点")
else:
    print("不好意思,您的机会已经用完,请下次再猜")
5.任意猜数字
guess_num_game = 66count =0while count < 3:    guess_age = int(input("guess_age:"))    
    if guess_num == guess_num_game:
print("恭喜你,才对了")
break
elif guess_num>guess_num_gane:
print("再小一点")
else:
print("再大一点")
count +=1  
 if count ==3:        
       countine = int(input("你想继续猜吗...? 1:继续 2:退出:"))        
 if countine ==1:      
          count = 0       
    else:           
       print("游戏结束,退出")            
 break
else:
    print("不好意思,您的机会已经用完,请下次再猜")