2025-08-22 12:19:39 +08:00

29 lines
903 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 提示用户输入信息
name = input("请输入你的名字:") # 程序会等待用户输入名字
print(f"{name}您好!")
age = input("请输入您的年龄:") # 程序会等待用户输入年龄
print(f"您的年龄是{age}")
"""
基础:让用户输入自己的名字,然后输出 “你好,[名字]!”
"""
name = input("请输入你的名字:")
print(f"你好,{name}")
"""
应用:让用户输入两个数字,然后输出它们的和(提示:记得用 int() 转换)
"""
num_1 = int(input("请输入第一个数字:"))
num_2 = int(input("请输入第二个数字:"))
print(f"他们的和是:{num_1 + num_2}")
"""
挑战:让用户输入一个数字,判断它是奇数还是偶数(提示:用 % 计算余数)
"""
num_1 = int(input("请输入一个数字:"))
if num_1 % 2 == 0:
print(f"{num_1}是偶数")
else:
print(f"{num_1}是奇数")