【习题4】变量和命名【第5天】
【代码】
#coding:utf-8 # 车的总数 cars=100 #每个车可以载人的数量,别问我为什么是浮点数^_^ space_in_a_car=4.0 #司机总数 drivers=30 #乘客总数 passengers=90 #多出的车的数量 cars_not_driven=cars-drivers #使用的车的数量=司机数量 cars_driven=drivers #可以拼车的承载力=可以使用的车数*每个车可以载人的数量,别问我为什么是浮点数^_^ carpool_capacity=cars_driven * space_in_a_car average_passengers_per_car=passengers/cars_driven print "There are ", cars,"cars available" print "There are only", drivers ,"drivers available." 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 ",average_passengers_per_car,"in each car."
关于出现的错误:SyntaxError: Non-ASCII character
出现问题的原因:程序中的编码错误,python默认是acii模式,没有支持utf8,代码的第3行中出现了中文注释,所以出现了错误。
插入第一行代码:#coding:utf-8,这样就可以避免了
【运行结果】
上传图片什么的好烦的,所以在python学完之后我统一上传。