Python学习Day1
北京实习元宵值班,学习Python基础
1.声明变量并赋值打印
name = "Hello World"
print(name)
2.交互输入变量值
name = input("Please input your name")
3.输出变量类型
name = "Hello World"
print(type(name))
4.变量类型转换
age = int(input("age:"))
例子:
name = input("name:")
age = int(input("age:"))
job = input("job:")
info = '''
---------info of %s ----------
Name:%s
Age:%s
Job:%s
'''%(name,name,age,job)
print(info)
info2 = '''
---------info of {_name} ----------
Name:{_name}
Age:{_age}
Job:{_job}
'''.format(_name=name,_age=age,_job=job)
print(info2)
5.if 用法
age = int(input("age:"))
if age == 40:
print("Yes")
elif age < 40:
print("small")
else:
print("big")
6.while 用法(可以配合使用 else )
count = 0
while count < 3:
print(count)
count += 1
else:
print("Count is too biger")
例子:猜年龄
count = 0
while count < 3:
guess_age = int(input("Guess age:"))
if guess_age == age_of_oldboy:
print("yes")
elif guess_age < age_of_user:
print("small")
else:
print("big")
count += 1
if count == 3:
continue_confim = input("Do you want to go on?")
if continue_confim != 'n':
count = 0
else:
print("The times is too much go out")
7.for 用法
#range 从 0 输出到 9
for i in range(10):
print(i)