在Python中重复函数
如何在python中重复函数。例如重复。。。其他语言的Unil。谢谢,这是我想重复的代码:在Python中重复函数,python,function,repeat,Python,Function,Repeat,如何在python中重复函数。例如重复。。。其他语言的Unil。谢谢,这是我想重复的代码: import random line = random.choice(keywords) print('Keyword:') print (line) line = random.choice(definitions) print ('A:') print (line) line = random.choice(definitions) print ('B:') print(line) line
import random
line = random.choice(keywords)
print('Keyword:')
print (line)
line = random.choice(definitions)
print ('A:')
print (line)
line = random.choice(definitions)
print ('B:')
print(line)
line = random.choice(definitions)
print ('C:')
print(line)
#randomly selects a keyword and definition from the file
A = []
ans = input('Is it A, B or C?')
print()
if ans == 'A' :
print ('Correct')
else:
print ('Incorrect')
#asks the user for an answer, then tells them if their correct or not
任何帮助都将不胜感激 无限循环(或直到满足特定条件):
这将在一个无休止的循环中调用您的代码,直到条件_to_break
为True
,然后中断循环
您可以阅读有关while
循环的更多信息
如果您想重复n
次,请尝试使用for
循环(阅读更多内容)
你是说像
而还是而不是?
如果您的意思是do-while
,那么在python中就有点棘手了,因为python没有
具有内置的功能,但您可以这样做:
while(True):
your_code_here()
if(your_exit_term): break
我知道这很难看,但我不熟悉其他任何方式。多少次了?你为什么不用谷歌搜索呢?Python支持“for”和“while”,但并不完全清楚你想做什么
for x in range(3):
# This code will execute 3 times
print("Executed {0} times".format(x+1))
while(True):
your_code_here()
if(your_exit_term): break