1.安裝環(huán)境
安裝pycharm和Anaconda
2.python版本的區(qū)別
python2.X 面向過程
python3.X 面向?qū)ο?br>
技術(shù)更新不再支持2.X版本
3.標識符與變量命名
ul li
java 字母數(shù)字下滑線洲愤,美元符摇幻, 且不能以數(shù)字開頭
c横侦、python 字母數(shù)字下滑線、 且不能以數(shù)字開頭
ol
1绰姻、駝峰式命名法枉侧、下滑線命名
大駝峰 :UserNameInfo
小駝峰: userNameInfo
下劃線:user_name_info
2、python3可以使用中文命名狂芋。但是不建議
變量1 = 'hehe'
print(變量1) 輸出語句
4.類型轉(zhuǎn)換與if...else...語句
age = input("請輸入您的年齡")
print(type(age))
print(age)
age = int(age)
print(type(age))
age = 8
if(age>=18):
print("真年輕")
else:
print("太老了")
5.else if 簡寫 elif
score = input("請輸入成績:")
score = int(score)
if score>=90 and score<=100:
print('您的成績?yōu)锳')
elif score >=80 and score<90:
print('您的成績等級為B')
elif score>=70 and score<80:
print('您的成績?yōu)镃')
elif score>=60 and score<70:
print('您的成績?yōu)镈')
else:
print('您的成績?yōu)镋')
6.while循環(huán)
#while 要判斷的條件:
#循環(huán)體
i = 0
while i<5:
print(i)
i +=1
#計算1-100相加之和
i = 1
s=0
while i <=100:
s +=i
i+=1
print(s)
7.break和continue跳出循環(huán)區(qū)別
break 跳出本層循環(huán)
continue 跳出本次循環(huán)棵逊,執(zhí)行下次循環(huán)
# 當累加和大于1000時跳出循環(huán)
i = 1
sum = 0
while i <= 100:
sum += i
if sum > 1000:
break
i += 1
print(sum)
7.猜數(shù)字游戲
隨機整數(shù)的生成
from random import randint
randint(start, end)
#1.準備知識
# from 模塊名 import name1,name2...(對象银酗,例如函數(shù)辆影,類)
#eg:
# hero_name = '魯班七號'
# grade = 15
# print('你選擇的英雄是{}當前等級為{}級'.format(hero_name,grade))
# python不允許這種寫法 print('你選擇的英雄是'+hero_name+'當前等級為'+grade+'級')
# 2.游戲規(guī)則
# 控制臺輸入要猜數(shù)字的范圍
# 請您輸入要猜數(shù)字的最大值
# 請您輸入要猜數(shù)字的最小值
# 輸入要猜的數(shù)字
# 程序告訴玩家猜大了還是猜小了,知道猜對數(shù)字結(jié)束循環(huán)
# 統(tǒng)計猜數(shù)字的次數(shù)
# 1次猜對黍特, 這是高手i次竟然就猜對
# 2~5 次猜對 蛙讥, 你也太厲害吧, i次猜對了
# 5次以上 你也太菜了灭衷,i次才猜對次慢,洗洗睡吧
from random import randint
a = int(input('請輸入數(shù)字的最小值'))
b = int(input('請輸入數(shù)字的最大值'))
c = randint(a, b)
i = 0
while True:
i += 1
d = int(input('請輸入你要猜的數(shù)字'))
if d < c:
print('你猜小了哦')
elif d > c:
print('你猜大了哦')
else:
if i == 1:
print('高手啊,{}次就猜對'.format(i))
elif i >= 2 and i <= 5:
print('你也太厲害吧翔曲, {}次猜對了'.format(i))
else:
print('你也太菜了迫像,{}次才猜對,洗洗睡吧'.format(i))
break
8.插入圖片
陳情令