Python获取控制台输入并进行相关操作的代码
代码演示了Python从键盘上获取用户在命令提示符下的输入信息的方法,并对输入的数据进行存储和使用。
""" 皮蛋编程(https://www.pidancode.com) 创建日期:2022/4/25 功能描述:Python获取控制台输入并进行相关操作的代码 """ name = input('What is your name? ') print("Hello,", name) age = eval(input('How old are you? ')) print('Age =', age, type(age)) base = eval(input('Enter the base: ')) height = eval(input('Enter the height: ')) area = base * height / 2 print('Area = ', area)
输出:
What is your name? pidancode Hello, pidancode How old are you? 10 Age = 10 <class 'int'> Enter the base: 4 Enter the height: 5 Area = 10.0
相关文章