# 1.第一个代码:输出语句
# 1.第一个代码:输出语句
print("My dog's name is Huppy!")
print('o----')
print(' ||| ')
print("*" * 10)
"""
输出结果:
My dog's name is Huppy!
o----
|||
**********
"""
# 2.变量
# 2.变量
price = 10
rating = 7.7
name = 'Mosh'
is_True = True
print(price, rating, name, is_True)
"""
输出结果:
10 7.7 Mosh True
注意事项:
Python的变量不需要定义类型
Python严格区分大小写,True不能为小写
"""
练习:输出一个全名叫Ma Baoguo的成年人,年龄18岁,是一个新人
full_name = 'Ma Baoguo'
age = 18
is_new = Ture
# 3.接受与输入
name = input('What is your name? ')
print('My name is ' + name + '.')
"""
输出结果:
What is your name? CDNS
My name is CDNS
"""
练习:你的名字是什么?你住在哪里?
print('What is your name?')
name = input()
print('Where is your address?')
is_address = input()
print('My name is ' + name + '. My address is ' + is_address + '.')
# 4.型号转换
# 4.型号转换
birth_year = input('Birth year: ') # birth_year是字符型
print(type(birth_year)) # 输出类型 :<class 'str'>
age = 2023 - int(birth_year) # Python中的强制类型转换
print(type(int(birth_year))) # <class 'int'>
print(age)
"""
输出结果:
Birth year: 2000
<class 'str'>
<class 'int'>
23
注意事项:
Python中的强制类型转换是:类型符(变量名)
Python输出语句中字符串不可与数字用 + 连接
"""
练习:输入一个重量(单位:磅)转换为(单位:千克),并输出 注意:1 kg 等于 0.45 lbs
weight_lbs = input('weight_lbs: ')
weight_kg = int(weight_lbs) * 0.45
# print("weight_kg: " + weight_kg) # TypeError: can only concatenate str (not "float") to str
print("weight_kg: " + str(weight_kg))
print("weight_kg: ", weight_kg)