# 学习配套书籍:https://www.jianshu.com/u/949b399ab14e
# C:\\Users\\acanprince\\Desktop\\Project\\lpthw
# No.1
print(“Hello World!”)
print(“Hello Again”)
print(“I like typing this.”)
print(“This is fun.”)
print(‘Yay!Printing.’)
print(“I’d muck rather you ‘not’.”)
print(‘I “said do not touch this.’)
# No.2
This is my # s test.
print(“Hi # is here.”)
print(“I will now count my chickens:”)
print(“Hens”,25 + 30 / 6)
# 果然先是乘除后是加减
print(“Roosters”,100 - 25 * 3 % 4)
print(“Now I will count the eggs:”)
print(3 + 2 + 1 - 5 + 4 % 2 - 1 / 4 + 6)
print(“Is it true that 3 + 2 < 5 - 72?”)
print(3 + 2 < 5 - 72)
print(“What is 3 + 2?”,3 + 2)
print(“What is 5 - 7?”,5 - 7)
print(“Oh, that’s why it’s False.”)
print(“How about some more.”)
print(“Is it greater?”,5 > -2)
print(“Is it greater or equal?”, 5 >= -2)
print(“Is it less or equal?”, 5 <= -2)
# python当中 整数和浮点数的比较:
print(“————————“)
print(“注意’is’ & ‘==’区别.python当中 整数和浮点数的比较:”)
a = 10
b = 10
c = 100
d = 100
e = 10.0
f = 10.0
print(a is b)
print(c is d)
print(e is f)
print(a == e)
print(a is e)
print(“————————“)
print(“注意 整数 和 浮点数的计算,会产生无限循环小数:”)
print(3.14 - 3.0)
print(‘’’在python中不建议直接将两个浮点数进行大小比较,
或者做精确的计算,往往会得到意想不到的结果。当然,如果非要用,
可以参考decimal模块的相关内容。’’’)
# 测试python相关Decimal模块进行浮点数运算
from decimal import Decimal
print(“测试使用Decimal模块进行浮点数计算:”)
a = Decimal(‘3.14’)
b = Decimal(‘3.0’)
print(“Decimal函数:a - b = “,a - b)
# — coding:utf-8 —
# 格式化 字符串和变量打印
# 更多的变量和打印
my_name = ‘Jiahao Zhang.AClear Zhang’
my_age = 22 #not a lie
my_height = 72 # inches
my_weight = 78 # kg
my_eyes = ‘Brown’
my_teeth = ‘White’
my_hair = ‘Black’
print(“Let’s talk about %s.” % my_name)
print(“He’s %d inches tall.” % my_height)
print(“He’s %d kg heavy.” % my_weight)
print(“Actually that’s not too heavy.”)
print(“He’s got %s eyes and %s hair.” % (my_eyes, my_hair))
print(“His teeth are usually %s depending on the coffe.” % my_teeth)
print(“\\n\\n—-Another way to print.—-“)
print(f”Let’s talk about {my_name}.”)
print(f”He’s {my_height} inches tall.”)
print(f”He’s {my_weight} kg heavy.”)
print(f”Actually that’s not too heavy.”)
print(f”He’s got {my_eyes} eyes and {my_hair} hair.”)
print(f”His teeth are usually {my_teeth} depending on the coffe.”)
# And this line is tricky, try to get it exactly right.
total = my_age + my_height + my_weight
print(f”If I add {my_age}, {my_height}, {my_weight} then I got {total}.”)
—-Another exercise—-
# 附加练习
height = 72 # inches
centimeters = height / 3.28 100
weight = 171.96 # pound
kilograms = weight 0.4536
print(f’’’\\nStudy Drills:I’m {height} inches or {round(centimeters, 2)} centimeters.
And My weight is {weight} pound or {round(kilograms, 2)} kilograms.\\n’’’)
# ex6.py 查找一个字符串放进另外一个字符串的地方 四个点
types_of_people = 10
x = f”There are {types_of_people} types of people.” # 外面也是可以进行 F-string 格式化的!
binary = “binary”
do_not = “don’t”
y = f”Those who know {binary} and those who {do_not}.” # 外面进行 F-string 格式化!
print(x)
print(y)
print(f”I said: {x}”) # No1
print(f”I also said: {y}”) # No2
hilarious = False
joke_evaluation = “Isn’t that joke is funny?! {}”
print(joke_evaluation.format(hilarious)) # 王牌学习 点! # No3
w = “This is the left side of……”
e = “a string with a right side.”
print(w + e) # 注意 是放置在一行上面。 # No4
# weight = 78 # kg
# pound = weight / 0.4536
# print(f”Now the {weight} kg translate into pound is {round(pound, 2)} pound.”)