代码:
import random list=["xyla","tom","hrh","monkey","c","b","a","2","1"] i=int(input("Please enter an integer: ")) while i!=100: j=random.sample(list,1) print(j) i=int(input("Please enter an integer: "))
效果:
Please enter an integer: 1 ['monkey'] Please enter an integer: 1 ['a'] Please enter an integer: 1 ['xyla'] Please enter an integer: 1 ['2'] Please enter an integer: 11 ['b'] Please enter an integer: 100
总结:
- 真的条件一定要设计好,另外i要有初值,否则无限循环。