1. 输出"Hello, World!"的代码:
print("Hello, World!")
  1. 计算两个数字之和的代码:
a = 10
b = 5
sum = a + b
print("The sum of", a, "and", b, "is", sum)
  1. 判断一个数是否为偶数的代码:
num = 4
if num % 2 == 0:
    print(num, "is even")
else:
    print(num, "is odd")
  1. 循环输出列表中的元素的代码:
fruits = ["apple", "banana", "cherry"]
for fruit in fruits:
    print(fruit)
  1. 定义一个函数并调用的代码:
def greet(name):
    print("Hello, " + name + "!")

greet("Alice")
编写一些简单的代码

原文地址: https://www.cveoy.top/t/topic/fhUT 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录