Python 第一个 Python 程序
“Hello World” 程序通常是初学者学习新编程语言时编写的第一个程序。它是一个简单的程序,将短语 “Hello, World!” 打印到控制台上。
任务
创建一个程序,提示用户输入他们的名字,然后使用该名字打印一个 “你好,xx!” 的问候消息。
JavaScript 实现
hello.js
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
rl.question('请输入你的名字:', (answer) => {
console.log(`你好,${answer}!`);
rl.close();
});
在终端中运行 node hello.js
命令以运行以上示例代码。
Python 实现
hello.py
name = input("请输入你的名字:")
print(f"你好,{name}!")
在终端中运行 python hello.py
命令以运行以上示例代码