找回密码
 中文实名注册
查看: 147|回复: 9

【Python作业】 周星宇

[复制链接]

5

主题

125

帖子

2185

积分

金牌会员

Rank: 6Rank: 6

积分
2185
发表于 2022-8-20 17:16:19 | 显示全部楼层 |阅读模式
本帖最后由 周星宇 于 2024-7-8 21:04 编辑

作业 帖子
回复

使用道具 举报

1

主题

29

帖子

291

积分

中级会员

Rank: 3Rank: 3

积分
291
发表于 2024-7-27 09:12:59 | 显示全部楼层
666666666666666666666666666666666
回复

使用道具 举报

5

主题

125

帖子

2185

积分

金牌会员

Rank: 6Rank: 6

积分
2185
 楼主| 发表于 2024-7-25 17:07:38 | 显示全部楼层

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?中文实名注册

x
回复

使用道具 举报

5

主题

125

帖子

2185

积分

金牌会员

Rank: 6Rank: 6

积分
2185
 楼主| 发表于 2024-7-8 21:08:23 | 显示全部楼层

csp-J 2023 T3 一元二次方程

[C++] 纯文本查看 复制代码
#include <bits/stdc++.h>
using namespace std;
bool out1(int a,int b){
	int g=__gcd(int(fabs(a)),int(fabs(b)));
	a/=g;
	b/=g;
	if(a==0){
		return false;
	}else if(b==1){
		cout<<a;
	}else{
		cout<<a<<"/"<<b;
	}return true;
}
void out2(int a,int in,int b){
	int g=__gcd(int(fabs(a)),int(fabs(b)));
	a/=g;
	b/=g;
	if(a!=1 && b!=1){
		printf("%d*sqrt(%d)/%d\n",a,in,b);
	}else{
		if(a!=1){
			printf("%d*",a);
		}printf("sqrt(%d)",in);
		if(b!=1){
			printf("/%d",b);
		}cout<<endl;
	}
}
int main(){
	int t,m;
	cin>>t>>m;
	for(int i=1;i<=t;i++){
		int a,b,c;
		cin>>a>>b>>c;
		if(a<0){
			a=-a,b=-b,c=-c;
		}int delta=pow(b,2)-4*a*c;
		double delta_sq=sqrt(delta);
		if(delta<0){
			cout<<"NO"<<endl;
		}else if(delta>=0){
            if(pow(int(delta_sq),2)==delta){
                if(ceil((-b+delta_sq)/(a*2))==(-b+delta_sq)/(2*a)){
                    cout<<(-b+delta_sq)/(a*2)<<endl;
                }else{
                    out1(-b+delta_sq,a*2);
                    cout<<endl;
                }
            }else{
                int num=1,in=delta;
                for(int j=2;j<delta_sq;j++){
                    if(delta%(j*j)==0){
                        num=j;
                        in=delta/(j*j);
                    }
                }if(out1(-b,2*a)==true){
                    cout<<'+';
                }out2(num,in,2*a);
            }
        }
	}return 0;
}


教学视频:【2023CSP-J真题】一元二次方程_哔哩哔哩_bilibili
回复

使用道具 举报

5

主题

125

帖子

2185

积分

金牌会员

Rank: 6Rank: 6

积分
2185
 楼主| 发表于 2023-4-9 12:04:18 | 显示全部楼层
[Python] 纯文本查看 复制代码
import turtle
# 模块一 初始化模块
turtle.setup(800, 600)  # 设置窗口大小
turtle.bgpic('坐标背景图.png')  # 加载默认背景
tutu = turtle.Turtle()  # 召唤图图
tutu.penup()  # 画笔抬起
# 模块二 基础形状模块
# 画圆形
def draw_circle(radius, color):  # 半径,颜色
    tutu.pendown()  # 画笔落下
    tutu.color(color)  # 将画笔和填充颜色同时设置为 color
    tutu.begin_fill()  # 开始填色
    tutu.circle(radius)
    tutu.end_fill()  # 结束填色
    tutu.penup()  # 画笔抬起
# 画长方形
def draw_rectangle(width, height, color):  # 宽度, 高度, 颜色
    tutu.pendown()  # 画笔落下
    tutu.color(color)  # 将画笔和填充颜色同时设置为 color
    tutu.begin_fill()  # 开始填色
    for i in range(2):
        tutu.forward(width)
        tutu.left(90)
        tutu.forward(height)
        tutu.left(90)
    tutu.end_fill()  # 结束填色
    tutu.penup()  # 画笔抬起
# 画三角形
def draw_triangle(length, color):  # 边长, 颜色
    tutu.pendown()  # 画笔落下
    tutu.color(color)  # 将画笔和填充颜色同时设置为 color
    tutu.begin_fill()  # 开始填色
    for i in range(3):
        tutu.forward(length)
        tutu.left(120)
    tutu.end_fill()  # 结束填色
    tutu.penup()  # 画笔抬起
# 模块三 按键绘制模块
# 功能一 屏幕点击功能
turtle.onscreenclick(tutu.goto, 1)
# 功能二 按键控制功能
# 画脸
def draw_face():
    draw_rectangle(200, 100, 'LemonChiffon')
# 画眼睛
def draw_eyes():
    draw_circle(12, 'IndianRed')
# 画嘴巴
def draw_mouth():
    draw_triangle(12, 'IndianRed')
# 画耳朵
def draw_ears():
    draw_rectangle(12, 40, 'IndianRed')
# 画身体
def draw_body():
    # 画长方形的脖子
    for i in range(4):
        x = tutu.xcor()
        y = tutu.ycor()
        draw_rectangle(60, 4, 'LightSalmon')
        tutu.goto(x, y-8)
    # 画圆圆的肚子
    x = tutu.xcor()
    y = tutu.ycor()
    tutu.goto(x+30, y)
    draw_circle(-150, 'LemonChiffon')
    # 画肚子上的三角形
    x = tutu.xcor()
    y = tutu.ycor()
    tutu.goto(x - 50, y - 100)
    draw_triangle(100, 'Khaki')
# 【你需要在这里完成【画天线】的模块】
def draw_antenna():
    x = tutu.xcor()
    y = tutu.ycor()
    draw_rectangle(60, 20, 'IndianRed')
    tutu.goto(x+25, y+20)
    draw_rectangle(5, 30, 'IndianRed')
    tutu.goto(x+45, y+20)
    draw_rectangle(5, 45, 'IndianRed')
# 按键事件语句
turtle.onkeypress(draw_face, '1')
turtle.onkeypress(draw_antenna, '2')
turtle.onkeypress(draw_eyes, '3')
turtle.onkeypress(draw_mouth, '4')
turtle.onkeypress(draw_ears, '5')
turtle.onkeypress(draw_body, '6')
# 监听语句
turtle.listen() 
# 启动事件循环
turtle.done()
回复

使用道具 举报

5

主题

125

帖子

2185

积分

金牌会员

Rank: 6Rank: 6

积分
2185
 楼主| 发表于 2023-4-1 17:31:31 | 显示全部楼层
[Python] 纯文本查看 复制代码
import turtle
import random
from tool import
turtle.setup(800,600)
turtle.speed(0)
turtle.pensize(10)
def rectangle(width,height):
    turtle.pendown()
    color_list=['red','yellow','blue','white','pink','green']
    turtle.fillcolor(random.choice(color_list))
    turtle.begin_fill()
    for i in range(2):
        turtle.forward(width)
        turtle.left(90)
        turtle.forward(height)
        turtle.left(90)
    turtle.end_fill()
    turtle.penup()
width_list=[]
height_list=[]
for i in range(5):
    width_list.append(random.randint(100,120))
    height_list.append(random.randint(60, 90))
print(width_list)
print(height_list)
x=0
y=0
for width in width_list:
    for height in height_list:
        rectangle(width, height)
turtle.done()
回复

使用道具 举报

5

主题

125

帖子

2185

积分

金牌会员

Rank: 6Rank: 6

积分
2185
 楼主| 发表于 2022-9-24 17:24:37 | 显示全部楼层

第三单元 第四节课 布尔游乐园

[Python] 纯文本查看 复制代码
age=float(input('请输入年龄'))
height=float(input('请输入身高'))
if age>=12 and height>=1.3:
    print('你可以玩过山车')
else:
    print('你不可以玩过山车')
for i in range(70,200):
    if i%2==1:
        print('是奇数')
    else:
        print('是偶数')
回复

使用道具 举报

5

主题

125

帖子

2185

积分

金牌会员

Rank: 6Rank: 6

积分
2185
 楼主| 发表于 2022-9-3 16:59:55 | 显示全部楼层
本帖最后由 周星宇 于 2022-9-3 17:25 编辑

[Python] 纯文本查看 复制代码
def jump(height,planet):
    if planet == '月球':
        result=height*6
    if planet == '火星':
        result = height*2.5
    if planet == '木星':
        result = height*0.4
    if planet == '中子星':
        result=height*0.001
    sentence=('你可以在'+planet+'跳'+str(result))
    print(sentence)
jump(0.5,'月球')
回复

使用道具 举报

5

主题

125

帖子

2185

积分

金牌会员

Rank: 6Rank: 6

积分
2185
 楼主| 发表于 2022-8-20 17:32:24 | 显示全部楼层

第三单元 第二课 火力支援

[Python] 纯文本查看 复制代码
def cal(days):
    result=2**days
    print(result)
    return result

if cal(10)<100:
    print('问题不大')
else:
    print('出大事了')

回复

使用道具 举报

5

主题

125

帖子

2185

积分

金牌会员

Rank: 6Rank: 6

积分
2185
 楼主| 发表于 2022-8-20 17:31:04 | 显示全部楼层

第三单元 第一课 折扣计算机

[Python] 纯文本查看 复制代码
def count(price_list):
    total = sum(price_list)
    if total >= 200:
        result=total*0.6
    elif total >=100:
        result=total*0.7
    else:
        result=total*0.8

count(10)

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 中文实名注册

本版积分规则

小黑屋|东台市机器人学会 ( 苏ICP备2021035350号-1;苏ICP备2021035350号-2;苏ICP备2021035350号-3 )

GMT+8, 2024-9-8 10:14 , Processed in 0.043399 second(s), 30 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表