Python 代码示例:用户输入信息并显示结果
以下是 Python 代码示例,用于获取用户输入并显示结果:
first_name = input('Please enter the first name: ')
last_name = input('Please enter the last name: ')
age = input('Please enter the age: ')
gender = input('Please enter the gender: ')
country_of_birth = input('Please enter the country of birth: ')
job_title = input('Please enter the job title: ')
print('Name:', first_name, last_name)
print('Age:', age)
print('Gender:', gender)
print('Country of birth:', country_of_birth)
print('Job title:', job_title)
运行结果:
Please enter the first name: John
Please enter the last name: Smith
Please enter the age: 25
Please enter the gender: Male
Please enter the country of birth: USA
Please enter the job title: Software Engineer
Name: John Smith
Age: 25
Gender: Male
Country of birth: USA
Job title: Software Engineer
该代码首先使用 input() 函数获取用户输入的姓名、年龄、性别、出生国家和职位。然后,使用 print() 函数将获取的信息以指定的格式输出到屏幕上。
该示例展示了 Python 中的基本输入输出操作和字符串拼接技巧,可以帮助初学者理解 Python 代码的基本结构和功能。
原文地址: https://www.cveoy.top/t/topic/owdY 著作权归作者所有。请勿转载和采集!