输入圆的半径R,调用自定义函数CircleArea()计算圆的面积并返回结果。(语言-python)

import math

① CircleArea(r):

area=math.pi*r*r

②   

R=float(input("请输入圆的半径R:")))

print("半径为{0}的圆面积为{1:.2f}".format(R, ③ ))

1、def
2、return area
3、CircleArea(R)

  • 这篇博客: 【python教程】-- 入门 | 小甲鱼《零基础入门学Python》教程笔记(知识点详细、源码可复制)全中的 示例 - circle方法绘制圆形 部分也许能够解决你的问题, 你可以仔细阅读以下内容或跳转源博客中阅读:
    • circle方法绘制圆形
    • circle(Surface, color, pos, radius, width=0)
    • Surface参数:绘制在surface对象上
    • color参数:颜色
    • pos参数:圆心位置
    • radius参数:半径大小
    • width=0:边框大小。0表示填充矩形,1以上表示 使用color指定的颜色绘制边框
    # 跟随鼠标的圆形
    import pygame
    import sys
    from pygame.locals import *
    
    pygame.init()
    
    WHITE = (255, 255, 255)
    BLACK = (0, 0, 0)
    GREEN = (0, 255, 0)
    RED = (255, 0, 0)
    BLUE = (0, 0, 255)
    
    size = width, height = 640, 480
    screen = pygame.display.set_mode(size)
    pygame.display.set_caption("FishC Demo")
    
    position = size[0] // 2, size[1] // 2
    moving = False
    
    clock = pygame.time.Clock()
    
    while True:
        for event in pygame.event.get():
            if event.type == QUIT:
                sys.exit()
    
            if event.type == MOUSEBUTTONDOWN:
                if event.button == 1:
                    moving = True
    
            if event.type == MOUSEBUTTONUP:
                if event.button == 1:
                    moving = False
    
        if moving:
            position = pygame.mouse.get_pos()
    
        screen.fill(WHITE)
    
        pygame.draw.circle(screen, RED, position, 25, 1)
        pygame.draw.circle(screen, GREEN, position, 75, 1)
        pygame.draw.circle(screen, BLUE, position, 125, 1)
    
        pygame.display.flip()
    
        clock.tick(120)