fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. // your code goes here
  13. }
  14. }
Success #stdin #stdout 0.07s 16528KB
stdin
🎄 字符圣诞树
 
复制代码:打开手机浏览器,进入 Ideone 等在线 Python 编辑器,复制下方代码。

height = 12
# 打印树冠
for i in range(height):
    print(' ' * (height - i - 1), end='')
    print('*' * (2 * i + 1))
# 打印树干
trunk_h = 3
for _ in range(trunk_h):
    print(' ' * (height - 2), end='')
    print('***')
print("\n🎄Merry Christmas!🎄")

运行代码:点击运行按钮,圣诞树会直接显示在终端输出区。
​
调整大小:修改  height  的数值,就能改变圣诞树的高度。
 
🎨 图形圣诞树
 
选择编辑器:在手机浏览器中打开 myCompiler 等支持 turtle 的在线 Python 编辑器。
​
复制代码:复制下方代码,粘贴到编辑器中。

import turtle
import random

# 屏幕设置(适配手机竖屏)
screen = turtle.Screen()
screen.setup(width=375, height=700)
screen.title("Merry Christmas")
screen.bgcolor("midnight blue")

# 画笔初始化
pen = turtle.Turtle()
pen.speed("fastest")
pen.hideturtle()

# 绘制圣诞树函数
def draw_tree(depth, length):
    if depth == 0:
        return
    pen.forward(length)
    pen.left(30)
    draw_tree(depth - 1, length * 0.75)
    pen.right(60)
    draw_tree(depth - 1, length * 0.75)
    pen.left(30)
    pen.backward(length)

# 绘制装饰球
def draw_ornament(x, y, color):
    pen.penup()
    pen.goto(x, y)
    pen.pendown()
    pen.color(color)
    pen.begin_fill()
    pen.circle(5)
    pen.end_fill()

# 绘制圣诞树
pen.color("forest green")
draw_tree(7, 100)

# 绘制装饰球
colors = ["red", "yellow", "blue", "white", "pink"]
for _ in range(10):
    x = random.randint(-60, 60)
    y = random.randint(-50, 50)
    color = random.choice(colors)
    draw_ornament(x, y, color)

turtle.done()
stdout
Standard output is empty