Python学习第一天记录
Python学习1根据笨方法学Python3进行练习学习,主要记录自己的学习历程和期间遇到的问题。
练习1.第一个程序ex1.py
#print("Hello World!")
#print("Hello Aagain.")
#print("I Like typing this.")
#print("This is fun.")
#print("Yay! Printing.")
#print("I'd much rather you 'not'.")
#print("I'said' do not touch this.")
print("test")
练习2.注释和 # 号
ex2.py
# A comment,this is so you can read your program later.
# Anything after the # ignored by python.
print("I could have code like this.") # and the comment after 5
# You can also use a comment to "disable" or comment out code
# print("This won't run.")
print("This will run.")
练习3.数字和数学
ex3.py
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 - 7?")
print("3 + 2 < 5 - 7")
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)
变量和名字
ex4.py
cars = 100 #车的数量
space_in_a_car = 4 #每个车的容量
drivers = 30 #司机数量
passengers = 90 #乘客数量
cars_not_driven = cars - drivers #不能使用的车
cars_driven = drivers #可使用的车
carpool_capacity = cars_driven * space_in_a_car #可使用车的总容量
averge_passengers_per_car = passengers / cars_driven #每辆车的乘客数量
print("There are", cars, "cars available.")
print("There are only", drivers, "drivers avaiable.")
print("There will be", cars_not_driven, "empty cars today.")
print("We can transport", carpool_capacity, "people today.")
print("We have", passengers, "to carpool today.")
print("We need to put about", averge_passengers_per_car,
"in each car.")



