Python共36篇

Python_上学期复习—课后作业

1.编写一个程序,能计算下面公式计算并输出 x 的值。 $$x=\frac{-b+\sqrt{b^{2}-4ac}}{2a}$$ 代码: a = int(input('请输入a的值:')) b = int(input('请输入b的值:')) c = int(input('请输入c...
北梦的头像-北梦の博客SVIP北梦1年前
02308

Python上课笔记

编写列表推导式1、将一组数字列表[1,2,3,4,5,6,7,8],每个数字都平方并除以2.l1 = [1, 2, 3, 4, 5, 6, 7, 8] print([i * i / 2 for i in l1])2、将一组字符串列表['apple','banana','cherry'],...
北梦的头像-北梦の博客SVIP北梦2年前
12051

Python课案例:计票机制

y = {} x = [] print('输入quit表示选手成绩录入完毕') while True: name = input('输入选手名称: \n') if name == 'quit': break score = float(input('请输入选手票数: \n')) y[name] = score...
珊瑚海的头像-北梦の博客珊瑚海2年前
019413

Python_函数练习题

1. 编写一个函数,该函数接收两个数字作为输入,并返回这两个数字的最大公约数。 def fun(x, y): while y != 0: temp = y y = x % y x = temp return x num1 = int(input('请输入第一个数字: '...
北梦的头像-北梦の博客SVIP北梦2年前
01817

数据类型综合练习

1.编写一个程序来反转一个字符串。例如,输入'Hello World'应输出'World Hello'。 str = input('请输入字符串:') str_list = str.split() new_str_list = ' '.join(str_list[::-1]) print(new_...
北梦的头像-北梦の博客SVIP北梦2年前
01687

Python第一学期期末考试_个人解题分享

由于众所周知的原因
北梦的头像-北梦の博客SVIP北梦1年前
01435

Python作业:函数

公约数# 编写一个函数,该函数接收两个数字作为输入,并返回这两个数字的最大公约数。 def gcd(a, b): while b != 0: a, b = b, a % b return a num1 = int(input('请输入一个整数:')) num2 = i...
珊瑚海的头像-北梦の博客珊瑚海2年前
011814

Python_练习_24.3.15

class Friend: def __init__(self): self.friend_li = {} # 实例方法 def welcome(self): print('欢迎来到好友管理系统') print('1.添加好友') print('2.删除好友') print('3.展示好友') print(...
北梦的头像-北梦の博客SVIP北梦1年前
011011

Python_练习_24.3.8

1.写出下列题目中的pyhon语句 定义一个Employee类(员工) 在员工类中定义类属性age(年龄)为40 定义一个方法displayCount(),输出“公司最高工资” 通过类Employee修改类属性age的值=35 在方...
北梦的头像-北梦の博客SVIP北梦1年前
01039

Python递归案例

把10不断处以2,直到不能除为止,打印每次的结果 def a(num): if num == 0: return 0 else: print(num) a(num // 2) a(10) 兔子数列 def f(month): if month < 3: return 1 else: return f(m...
北梦的头像-北梦の博客SVIP北梦2年前
010215