随笔分类 - ksxt python课外练习
摘要:样例输入 4 样例输出 (1)静夜思 李白 床前明月光, 疑是地上霜。 样例输入 6 样例输出 (1)静夜思 李白 床前明月光, 疑是地上霜。 举头望明月, 低头思故乡。 解题代码 #coding=gbk """【""" f=open("ANSI(GBK).txt","r",encoding="GB
阅读全文
摘要:样例输入 张三 男李四 女 19 样例输出 姓名:张三,性别:男 李四 女 19 姓名:王五,性别:?,年龄:29 解题代码 #coding=gbk #定义人的类 class Person(object):#继承object,它是所有类的基类、父类 def __init__(self,xm,xb):
阅读全文
摘要:样例输入 3 4 样例输出 3*4=12 4*5=20 未定义宽,未定义高 样例输入 6 7 样例输出 6*7=42 7*8=56 未定义宽,未定义高 解题代码 #coding=gbk class Rectangle: #定义长方形类 """【""" def getwidth(this): retu
阅读全文
摘要:样例输入 3 4 样例输出 3*4=12 4*5=20 未定义宽,未定义高 样例输入 6 7 样例输出 6*7=42 7*8=56 未定义宽,未定义高 解题代码 #coding=gbk class Rectangle: #定义长方形类 """【""" @property def width(this
阅读全文
摘要:样例输入 3 4 样例输出 3*4=12 4*5=20 未定义宽,未定义高 样例输入 6 7 样例输出 6*7=42 7*8=56 未定义宽,未定义高 解题代码 #coding=gbk class Rectangle: #定义长方形类 """【""" def __init__(this,width=
阅读全文
摘要:样例输入 4 5 样例输出 4+5=9 样例输入 6 7 样例输出 6+7=13 解题代码 #coding=gbk """【""" class NumberAdd: def __init__(this,a,b): this.a=a this.b=b def add(this): return thi
阅读全文
摘要:样例输入 2020 10 8 样例输出 October 08,2020 Thursday 参考答案 import datetime a,b,c=map(int,input().split()) d=datetime.datetime(a,b,c) print(d.strftime("%B %d,%Y
阅读全文
摘要:样例输入 5 样例输出 12 样例输入 6 样例输出 720 参考答案 def fact(n): result=1 for i in range(1,n+1): result*=i return result n=int(input("")) print(fact(n))
阅读全文
摘要:样例输出 Happy birthday to you! Happy birthday to me! Happy birthday to make! 参考答案 def happy(str="you"): print("Happy birthday to {}!".format(str)) happy(
阅读全文
摘要:样例输入 2 3 1 样例输出 (-0.5, -1.0) 样例输入 2 4 6 样例输出 输入错误,无解 解题代码 import math def fun(a,b,c): dt=b*b-4*a*c x1=(-b+math.sqrt(dt))/(2*a) x2=(-b-math.sqrt(dt))/(
阅读全文
摘要:参考文章 宝玉听了这话,公然又是一个袭人.因笑道:“我在这里坐着,你放心去罢。”麝月道:“你既在这里,越发不用去了,咱们两个说话顽笑岂不好?"宝玉笑道:“咱两个作什么呢?怪没意思的,也罢了,早上你说头痒,这会子没什么事,我替你篦头罢。”麝月听了便道:“就是这样。”说着,将具镜匣搬来,卸去钗钏,打开头
阅读全文
摘要:样例输入 12345 样例输出 5 [1, 2, 3, 4, 5] 样例输入 2573 样例输出 4 [2, 5, 7, 3] 参考答案 n=int(input()) a=str(n) print(len(a),end='') print(" [",end='') for i in range(le
阅读全文
摘要:样例输出 3 样例输出 45,100,39,平均成绩为61.33 样例输入 5 样例输出 45,17,97,47,36,平均成绩为48.40 题目说明 运行结果中随机整数成绩及平均成绩具体数值不考虑,只需保证生成随机数的范围、个数、结果精度及显示格式 参考答案 import random n=int
阅读全文
摘要:样例输入 123 24 样例输出 {'1', '2', '3'}&{'2', '4'}={'2'} 样例输入 1234 24 样例输出 {'1', '2', '3', '4'}&{'2', '4'}={'2', '4'} 解题代码 str1,str2 = map(str,input().split(
阅读全文
摘要:样例输入 2 样例输出 星期二 样例输入 4 样例输出 星期四 样例输入 7 样例输出 星期日 解题代码 a=int(input()) if a==1: print("星期一") elif a==2: print("星期二") elif a==3: print("星期三") elif a==4: p
阅读全文
摘要:样例输入 4 样例输出 2 3 样例输入 10 样例输出 2 3 5 7 解题代码 n=int(input()) for i in range(2,n): t=1 for a in range(2,i): if i%a==0: t=0 break if t==1: if i!=2: print("
阅读全文
摘要:样例输入 49 4 样例输出 4 样例输入 12 3 样例输出 3 解题代码 a,b=map(int,input().split()) if a>b: print(b) else: print(a)
阅读全文
摘要:提示 90及以上为优秀,80及以上为良好,70及以上为中,60以上为及格,否则不及格 样例输入 95 样例输出 优秀 样例输入 85 样例输出 良好 样例输入 75 样例输出 中 样例输入 65 样例输出 及格 解题代码 a=int(input()) if a>=90: print("优秀") el
阅读全文
摘要:样例输入 2 样例输出 二月 样例输入 10 样例输出 十月 样例输入 15 样例输出 输入有误 解题代码 a=int(input()) if a==1: print("一月") elif a==2: print("二月") elif a==3: print("三月") elif a==4: pri
阅读全文
摘要:样例输入 12345 样例输出 不是回文数 样例输入 12321 样例输出 是回文数 样例输入 1321 样例输出 输入有误 解题代码 str=str(input()) if(len(str)!=5): print("输入有误") else: a=0 if str[0]==str[-1] and s
阅读全文

浙公网安备 33010602011771号