Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
30 changes: 30 additions & 0 deletions homeworks/B21576/checkin01/day1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/python
#-*-coding:utf-8 -*-
#author:suancaiyu
#学习内容:了解python 变量(数值和字符串),if,print,编程的实质

def main():
who = 'suancaiyu的老妈'
good_price = 6 #或者把商品价格改成5。
good_description = "西双版纳大白菜"

is_cheap = False
reasonable_price = 5 #把这个合理价格改成6
buy_amount = 2


print "%s上街看到了%s,卖 %d 元/斤" % (who, good_description, good_price)

if good_price <= reasonable_price:
print '她认为很便宜'
is_cheap = True
print '她买了%d斤' % (buy_amount)
else:
print '她认为贵了'
is_cheap = False
print '她并没有买,扬长而去'


if __name__ == '__main__':
main()

32 changes: 32 additions & 0 deletions homeworks/B21576/checkin01/day1_homework.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# @author: suancaiyu
#学习内容:如果小贩的价格每降一元老妈就多买一斤 对应程序中的变量就量buy_amount

def main():
who = 'suancaiyu的老妈'
good_price = 5 #小贩的价格
good_description = '大白菜'

is_cheap = False #是否便宜
reasonable_price = 5 #老妈能接受的最高价格
buy_amount = 2 #准备买 2 斤

print "%s上街看到了%s,卖 %d 元/斤" % (who, good_description, good_price)

if good_price <= reasonable_price:
print '她认为便宜'
is_cheap = True
buy_amount = 2 + (reasonable_price - good_price)
if buy_amount > 4:
buy_amount = 4
print '她买了 %d 斤' % (buy_amount)
else:
print '她认为贵了'
is_cheap = False
print '她扬长而去'


# run function
if __name__ == '__main__':
main()
80 changes: 80 additions & 0 deletions homeworks/B21576/checkin01/day2_homework.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# @author: suancaiyu
#学习内容:
#1,练习python中运算符,和表达式 单个字符或数值可以构成表达式吗?
#2,print 语句输出格式化 %0.2f


def main():
apple_numbe = 5
apple_price = 4.8
pie_number = 6
pie_price = 6.782

apple_total_price = apple_numbe * apple_price
pie_total_price = pie_number * pie_price

print 'pie cost %d' % (pie_total_price) #pie的总价格 到整数
print 'pie cost %g' % (pie_total_price) #保留小数点
print 'pie cost %0.2f' % (pie_total_price) #保留小数点后两位 由f前的数字决定保留几位

number = 2**3 # ** 次方
print 'number = %d' % (number)

print 'test: %d' % (1 != 2) #!=不等于
print 'test: %d' % (1 >= 2)

if 1:
print 'goog' #不太清楚这边的if正确,是哪里正确了
if 0:
print 'xxx'

if(2 != 2):
print 'hello,world'


#p34的练习

#简单的加减乘除之类的
number = 2+3 #必须要缩进,不然会被忽视
print 'number = %d' %(number) #打完上面一行,得print才会在下面框框显示

number = 10%3 #//取商,即3; %取余数,即1.
print 'number = %d' %(number)

#比较
x = 'star'
y = 'stAr' #定义x,y 的时候,如果是字符,一定要加引号

if (x == y): #等于的符号是:==
print 'cool'

if (x != y):
print 'oh no'

#and,or not不会用
x = True #这个地方可以打True、False,也可以打1,0
y = 2**3
number = x and y # x如果是False,and 返回False 否则返回y的值
#or # x如果是True, or 返回Ture,否则返回y的值

print 'number =%d' %(number) #实在不知道这句话干嘛用的,但是好好用。先就用着吧



#对比大小的一种方式,好原始。
x = 5
y = 6

if x <= y:
print 'True'
else:
print 'False'

#对比大小 不需要定义
print '%d' %( 5 <= 6 )


if __name__ == '__main__':
main()
58 changes: 58 additions & 0 deletions homeworks/B21576/checkin01/day3_homework.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# @author: suancaiyu
# 学习内容:
#1,理解单一职责在编程中的应用 :如果同一变量,代码,功能在程序中重复引用超过3次,可以将它们单独定义在一个函数(也就量函数封装)
#2,实现记账函数record_account 输出老妈买菜的花销 ,学习函数的调用,函数的传参,函数的返回值,对函数返回值的引用
#3,实现函数定义老爸和老妈的对话,如果今天价格便宜就x斤,如果价格贵就不买

def record_account(is_cheap2, good_price2, buy_amount3):
if is_cheap2:
record_account = good_price2 * buy_amount3

print '妈妈回家拿出记账本,写下今天花了%d钱' % (record_account)


def talk_to_daddy(is_cheap3, buy_amount3):
if is_cheap3:
print '老妈回到家里,跟老爸说:“今天去买菜,价格不贵,买了%d斤”' % (buy_amount3)
else:
print '老妈回到家里,跟老爸说:"今天去买菜,菜好贵额,没买"。'

def buybuybuy():
good_price = 3 #是一个会变的数字,每降低1元,多买1斤
reasonable_price = 5
buy_amount = 2 #是一个会变的数字,每降低1元,多买1斤

who = 'suancaiyu的妈妈'
good_description = '西双版纳大白菜'

is_cheap = False

print '%s上街看到了 %s, 卖 %d 元/斤' % (who, good_description, good_price)

if good_price <= reasonable_price: # 这种结尾的冒号要特别注意,如果丢了的话要补上
print '她认为很便宜'
is_cheap = True

#开始考虑买几斤的问题 5-2 4-3 3-4 2-4 最多买四斤
buy_amount = 2 + (reasonable_price - good_price)

if buy_amount > 4:
buy_amount = 4

print '她买了 %d 斤' % (buy_amount)
else:
print '她认为贵了'
is_cheap = False
print '她并没有买,扬长而去'

return is_cheap, buy_amount, good_price

def main():
is_cheap2, buy_amount2,good_price2 = buybuybuy()
talk_to_daddy(is_cheap2, buy_amount2)
record_account(is_cheap2, good_price2, buy_amount2)

if __name__ == '__main__':
main()
21 changes: 21 additions & 0 deletions homeworks/B21576/checkin02/day4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# @author: suancaiyu
#学习bool型数据代表的意义 True, False
def main():
number = 1
number_2 = 1.5

string = '我是郭叔叔'

is_cheap = False # boolean型表示
is_cheap_2 = True


if number >= number_2: #分支判断
print string
else:
print '错了%f错了' %(number_2)

if __name__ == '__main__':
main()
28 changes: 28 additions & 0 deletions homeworks/B21576/checkin02/day5_homework.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/python
#-*- coding: utf-8 -*-
#@author:suancaiyu
#学习内容:列表:list 分支判断:for
#01)list: 可以将存放多个对象(包括字符串,数字,)的数据结构,避免用多个变量存放。那么列表可以存放
# 另外一个列表吗?
#02)for:可以逐一的使用列表的每一个对象,当同一相似的动作需要多次使用时利用循环
#03)pass 语句
def main():
list = ['dabaicai','kongxincai','huacai','shengjiang','xiaolongxia',9,2.3]
print(list)
for item in list: #输出列表中的全部元素
print item
list01 = list + ['apple','banana','rice'] #往列表中添加元素的操作
print list01
pass #python 中pass 表示什么也不做
print list01[0] # 打印列表的第0个元素? 列表中的元素是有序还是无序的?取得列表中某一个值。
print list01[-1]
pass
for item01 in list01:
print item01
# list02 = list01 - ['apple','rice'] #列表支持删除操作吗?

# for item02 in list02:
# print item02

if __name__=='__main__':
main()
92 changes: 92 additions & 0 deletions homeworks/B21576/checkin02/day6.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# @author: suancaiyu
#学习内容
#0. 定义一个列表:
#1. 利用for 迭代遍历列表中的元素,索引,
#2,列表的常用操作 求出列表的长度,删除,添加 ,取值,
def print_list(lst):
for lst_item in lst: #遍历
print '老妈看到了 %s '% (lst_item)

def main():
# 0 1 2 3 4
lst = ['大白菜', '空心菜', '花菜', '生姜', '小龙虾'] #列表
# 循环访问
for lst_item in lst: #遍历
# print '老妈看到了 %s '% (lst_item)
pass

# 记录下标
index = 0
for lst_item in lst: #遍历
# print '老妈看到了 %s '% (lst_item)
# print '当前第 %d 个' %(index)
index = index + 1

# 迭代访问
for index,lst_item in enumerate(lst):
# print '老妈看到了 %s '% (lst_item)
# print '当前第 %d 个' %(index)
pass

#取值
print lst[0]

#长度
print len(lst)

#加
lst.append('白芍')
print_list(lst)

#删除
# del lst[0]
print '---'
# print_list(lst)

#切片
lst2 = lst[2:5] # 2,3,4
print_list(lst2)




def main2():
# 记录下标
index = 0
for lst_item in lst:
print lst_item
print '第 %d 个' % (index)
index = index + 1

# 迭代访问
for index,lst_item in enumerate(lst):
print index
print lst_item

#取值
print lst[0]

#长度
length = len(lst) #5
print '该列表有 %d 个元素' % (length)

#加
lst.append('白芍')
length = len(lst) #6
print '该列表有 %d 个元素' % (length)

#删除
del lst[0] #删除了一个元素

#切片
lst2 = lst[1:4] #0,1,2

print lst2
for item in lst2:
print item


if __name__ == '__main__':
main()
Loading