Python_if语句。 Learn python the hard way_扩展练习。习题29

#coding=utf-8
#raw_input()函数输出的数据是"str",需要将其处理成数据,使用int()函数,将“str"转换成数据来处理
students = int(raw_input("students number"))  
fees_per_person = 80
cost = students * 3
total_income =  students * fees_per_person
total_profit = total_income - cost

print "Our total_income is : %d." % total_income
print "Our total_profit is : %d." % total_profit

if total_profit > 1000:
 print "\tWe are making big money now."
 
if total_profit > 5000:
 print "\tWe are making super money now."
 
if total_profit <= 10000:
 print "\tWe still need to work harder, to make more money."
 
if total_profit >= 10000:
 print "We don‘t need to work for the rest of the life."

时间: 2024-08-01 16:47:19

Python_if语句。 Learn python the hard way_扩展练习。习题29的相关文章

Learn Python the Hard Way--Exercise 46

0. 缘起 <Learn Python the Hard Way>Exercise 46 要求安装四个python package pip, distribute, nose, virtualenv,(原书作者特别提醒: Do not just donwload these packages and install them by hand. Instead see how other people recommend you install these packages and use th

Python selenium的js扩展实现

python写的数据采集,对一般有规律的页面用 urllib2 + BeautifulSoup + 正则就可以搞定. 但是有些页面的内容是通过js生成,或者通过js跳转的,甚至js中还加入几道混淆机制:对这种涉及页面脚本解析的内容,前面的方式便很无力. 这时我们需要能解析.运行js的引擎——浏览器,而python selenium能提供程序与浏览器的交互接口,再加上phantomjs这个可以后台运行的浏览器,即使用 selenium + phantomjs 便可以解决以上的问题. seleniu

[IT学习]Learn Python the Hard Way (Using Python 3)笨办法学Python3版本

黑客余弦先生在知道创宇的知道创宇研发技能表v3.1中提到了入门Python的一本好书<Learn Python the Hard Way(英文版链接)>.其中的代码全部是2.7版本. 如果你觉得英文版看着累,当当网有中文版,也有电子版可以选择. 我试着将其中的代码更新到Python 3.同时附上一些自己的初学体会,希望会对你有帮助. 中文版有人把书名翻译为<笨办法学python>,其实我觉得叫做<学Python,不走寻常路>更有意思些. 作者的意思你可以在序言中详细了解

Learn Python From &#39;Head First Python&#39; [3](2) : Pickle

1.the use of 'with open... as ...' 2.the use of pickle(dump and load) for Step1: the 'with open ... as...' is the short format of 'try...except...finally' for Step2: you can store a list with pickle.dump() and get the content again with pickle.load()

Learn Python From &#39;Head First Python&#39; [2] : Sharing

1.publish 2.update print_lol PS: for Step 1. write the code in to a py file. put the py file into a folder named nester. new a py file named 'setup' and the content as below: setup( name = 'nester', version = '1.0.0', py_modules = ['nester'], author

Learn Python From &#39;Head First Python&#39; [1] : The List

1.the concept of List 2. how to define a method of myself 3.how to iterator a list PS: for Step 2,3. it is related with a key word: 'def'. we define a function like below. def function name: XXXXX e.g. list iterator : 1 def print_lol(the_list): 2 for

MySQL常用SQL语句(Python实现学生、课程、选课表增删改查)

以基本的学生选课为例,建立选课数据库,学生.班级.选课信息三张表,并分别对表进行插删改操作: import MySQLdb try: conn = MySQLdb.connect(host = 'localhost', user = 'root', passwd = 'root', db = 'xuanke', port = 3306) cur = conn.cursor() cur.execute("CREATE DATABASE xuanke") cur.execute("

Learn Python From &#39;Head First Python&#39; [0] : Install

1. download software form the python‘s webset 2. install the python and set the class path 3. verify if the install is correct PS: for Step 2. if you use the default install. then undre the disk C:, there will be a dir like Python34. go to the env se

Learn Python From &#39;Head First Python&#39; [3] : Exception

1.the using of exception 2.file opration import os >>> try: data = open('sketch.txt') for each in data: try: (role,message) = each.split(':') print(role + ' says: ' + message, end='') except ValueError: pass data.close() except IOError: print('fi