Python函数在特定情况下如何实现递归调用?
- 内容介绍
- 文章标签
- 相关推荐
本文共计581个文字,预计阅读时间需要3分钟。
例如以下这个函数:
pythonstate=1
def set_state(state): while state: set=int(input('请输入9或5,显示hello world!\n')) if set==9 or set==5: print('hello world') state=int(input('输入1继续,输入0停止!\n')) print('程序结束。')
例如以下这个函数:
state = 1 def set_state(state): while state: set = int(input('请输入9或5,显示"hello world"\n')) if set == 9 or set == 5: print('hello world') state = int(input('输入1继续,输入0停止!\n')) else: print('请输入要求的值!') set_state(state) # break set_state(state) print('end')
这个函数设计的目的是让用户输入指定的值,若输入的值并非指定值,则重新输入。
本文共计581个文字,预计阅读时间需要3分钟。
例如以下这个函数:
pythonstate=1
def set_state(state): while state: set=int(input('请输入9或5,显示hello world!\n')) if set==9 or set==5: print('hello world') state=int(input('输入1继续,输入0停止!\n')) print('程序结束。')
例如以下这个函数:
state = 1 def set_state(state): while state: set = int(input('请输入9或5,显示"hello world"\n')) if set == 9 or set == 5: print('hello world') state = int(input('输入1继续,输入0停止!\n')) else: print('请输入要求的值!') set_state(state) # break set_state(state) print('end')
这个函数设计的目的是让用户输入指定的值,若输入的值并非指定值,则重新输入。

