初识python代码

1、初识代码

1 x = 3
2 y = 4
3 z = 3*4
4 
5 print("x乘以y=", z)
6 
7 print("z=", z)

2、Hello,World!

1 C:\Users\Administrator\Desktop\python>python
2 Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:59:51) [MSC v.1914 64 bit (AMD6
3 4)] on win32
4 Type "help", "copyright", "credits" or "license" for more information.
5 >>> print("Hello,World!")
6 Hello,World!

3、Windows测试中文显示(python2.x需要指定中文编码:utf-8);python3.x编码更新为Unicode,默认向下兼容所有编码

1 #!-*- coding:utf-8 -*-
2 
3 print ("我肚子饿了,想吃饭!")

4、if.....else语句初识

(猜年龄)

1 age_of_princal = 45
2 guess_age = int(input(">>:"))
3 
4 if guess_age == age_of_princal:
5     print("Yes,you got it..")    
6 else:
7     print("No,it's wrong!")

判定成绩

 1 score = int(input("score:"))
 2 
 3 if score > 90:
 4     print("A")
 5 elif score >80:
 6     print("B")
 7 elif score >70:
 8     print("C")
 9 elif score > 50:
10     print("D")
11 else:
12     print("你挂科啦")

猜你喜欢

转载自www.cnblogs.com/larryzhou/p/9260195.html