""" ====================== Author: 柠檬班-小简 Time: 2020/5/29 19:39 Project: py30 Company: 湖南零檬信息技术有限公司 ====================== """ """ 1、一家商场在降价促销,所有原价都是整数(不需要考虑浮点情况), 如果购买金额50-100元(包含50元和100元)之间,会给10%的折扣, 如果购买金额大于100元会给20%折扣。 编写一程序,询问购买价格,再显示出折扣(%10或20%)和最终价格。 input - 150 20% 150*(1-20%) 77 10% 77*(1-10%) 44 0 44 money * (1-discount) """ # money = input("购买价格:") # money_int = int(money) # if 50 <= money_int <= 100: # discount = 0.1 # elif money_int > 100: # discount = 0.2 # else: # discount = 0 # # print("折扣:{:.0%},最终要付的价格为:{}".format(discount,money_int*(1-discount))) """ 2、输入一个有效的年份(如:2019),判断是否为闰年(不需要考虑非数字的情况) 如果是闰年,则打印“2019年是闰年”;否则打印“2019年不是闰年” year 普通闰年:公历年份是4的倍数的,且不是100的倍数,为普通闰年。(如2004年就是闰年); year%4 ==0 and year%100 !=0 世纪闰年:公历年份是整百数的,必须是400的倍数才是世纪闰年 year % 400 == 0 """ # year = int(input("请输入年份:")) # if (year%4 ==0 and year%100 !=0) or year %400==0: # print("{}是闰年!".format(year)) # else: # print("{}不是闰年!".format(year)) """ 3.求三个整数中的最大值 提示:定义 3 个变量 100 150 55 """ # a = 55 # b = 100 # c = 100 # max_num = a # # 前2数相比,取最大值。 # if a < b: # max_num = b # # # 前2数的最大值,和最后一个比。 # if max_num < c: # max_num = c # print(max_num) """ 输出九九乘法表,格式如下:(每项数据之间空一个Tab键,可以使用"\t") 1 * 1 = 1 1 * 2 = 2 2 * 2 = 4 1 * 3 = 3 2 * 3 = 6 3 * 3 = 9 1 * 4 = 4 2 * 4 = 8 3 * 4 = 12 4 * 4 = 16 1 * 5 = 5 2 * 5 = 10 3 * 5 = 15 4 * 5 = 20 5 * 5 = 25 1 * 6 = 6 2 * 6 = 12 3 * 6 = 18 4 * 6 = 24 5 * 6 = 30 6 * 6 = 36 1 * 7 = 7 2 * 7 = 14 3 * 7 = 21 4 * 7 = 28 5 * 7 = 35 6 * 7 = 42 7 * 7 = 49 1 * 8 = 8 2 * 8 = 16 3 * 8 = 24 4 * 8 = 32 5 * 8 = 40 6 * 8 = 48 7 * 8 = 56 8 * 8 = 64 1 * 9 = 9 2 * 9 = 18 3 * 9 = 27 4 * 9 = 36 5 * 9 = 45 6 * 9 = 54 7 * 9 = 63 8 * 9 = 72 9 * 9 = 81 关系:{} * 行号 = 结果。 第1行 从1开始 1*1=1 1 第2行 从1开始 1*2 2*2 1,2 第3行 从1开始 1*3 2*3 3*3 1,2,3 {} * 行号 = 结果。 """ for row in range(1,10): for sub in range(1,row+1): print("{} * {} = {}".format(sub,row,sub*row),end="\t") print("")