Python return返回值
例:import random def getAn(answer): if answer == 1: return 'one' elif answer == 2: return 'tow' elif answer == 3: return 'three' elif answer == 4: retur
例:import random def getAn(answer): if answer == 1: return 'one' elif answer == 2: return 'tow' elif answer == 3: return 'three' elif answer == 4: retur
自定义函数例一:def hello(): print("K") print("J") print("I") print('\n') hello() hello() hello() 例二:def hello(name): print('hello '+name) hello("Alice
例:import syswhile True:print("Type exit to exit.") res = input("请输入:") if res == "exit": sys.exit() print("You type " + res +'.')
例一:导入随机数模块,显示5次1-10中的随机数import random for i in range(1,6): print(random.randint(1,10))
例一:打印名字5次:print('请输入名字5次') for i in range(5): i = i+1 print("Jim:",i) 等价的whileprint("输出5次名字") i=1 while i<6: print("Jim:",i) i+=1 例二:计算出0-100的和:total =
1.while 循环 语句spam = 0 while spam <5: print("Hello Word:",spam) spam +=1 2.while的break语句name = '' while name != "your name": print("Now your name:",name)
例子import random k = random.randint(1,20) print('这个数字在1到20之间') for i in range(1,7): y = int(input("请输入Y的值:")) if y<k: if y<1: print("输入的数字过小,请输入1至20之间的数