4.用户交互和格式化输出


# 用户交互
name=input("show me your name:")
age=int(input("show me your age:"))
hometown=input("show me your hometown:")

print(name)
print(age)
print(hometown)
if int(age)<10:
print("小朋友")

# 格式化输出

msg="""
-----info----
name: %s
age: %d
hometown:%s
-----end-----

"""%(name,age,hometown)

print(msg)

%f 浮点数
%s 包含所有类型
%d是数字
input 方法接收到的都是字符串。需转换成int 等
原文地址:https://www.cnblogs.com/xh716/p/11547002.html