学习while循环捏
#while循环
current_number=1;
while current_number<=5:
print(current_number)
current_number+=1
#让用户选择何时退出
prompt='i will repeat your words untill you say quit.'
message=''
while message!='quit':
message=input(prompt)
print(message)
#可设置flag
active=True
while active:
message = input(prompt)
if message == 'quit':
active = False
else:
print(message)
#使用break退出循环
active=True
while active:
message = input(prompt)
if message == 'quit':
break
else:
print(message)
#使用continue跳过后续,开启下一轮循环
#若不小心敲出无限循环,按ctrl+c关闭窗口
函数
#定义函数()
def greet_user():
print("Hello!")
greet_user()
def greet_user2(username):
print(f'Hello,{username.title()}')
greet_user2('jesse')
#位置实参必须按顺序赋值,关键字实参可不按顺序
def haha(first,next):
print(f'{first}{next}')
haha(1,2)
haha(next=2,first=1)
#赋予形参默认值,则在未给予实参时当作默认值
def hahaha(first,next=2):
print(f'{first}{next}')
hahaha(1)
#函数返回值
def get_formatted_name(first_name,last_name):
full_name=f'{first_name}{last_name}'
return full_name.title()
musician=get_formatted_name('jimi','hendrix')
print(musician)