# 1.三角形
n = 9
for i in range(n):
for j in range(i):
print(' ', end='')
for k in range(i, n):
print('*', end=' ')
print()
# 2.九九乘法表
for i in range(1, 10):
for n in range(1, i + 1):
print('%s×%s=%s' % (i, n, i * n), end=' ')
print()
3.使用for循环输出数字0-9,当数字为6时,跳出本次循环,执行其他循环当数字为8的时候,停止循环
for i in range(0,10):
if i == 6:
continue
elif i == 8:
break
else:
print(i)
4使用循环 计算出1-100之间 所有基数的和,偶数和
s = 0
for i in range(1,100):
if i % 2 == 0:
s += i
if i % 2 !=0:
s +=1
# else:
print(s)
偶数和
s = 0
for i in range(1,100):
if i % 2 == 0:
s +=i
print(s)
奇数和
s = 0
for i in range(1,100):
if i % 2!= 0:
s += i
print(s)
5.模拟ATM取钱系统,取款机里一共有10000元, # 有五个人分别去取钱,每次取钱的金额在100元到500元之间,
要求输出他们每次取钱的金额,以及ATM机里的余额,
当余额小于取款的金额时,退出系统。
import random
import os
import threading
import time
from threading import Thread, Lock
lock = Lock()
meon = 10000
def a(i):
while True:
global meon
time.sleep(1)
lock.acquire()
mon = random.randint(100, 500)
if mon <= meon:
meon -= mon
print("%s取了%d,剩余%d" % (i, mon, meon))
else:
print("余额不足")
os._exit(0)
lock.release()
if name == 'main':
list = ["张三", "李四", "王五", "赵六", "王七"]
for i in list:
t = threading.Thread(target=a, args=(i,))
t.start()
from functools import reduce
def fun(i):
return reduce(lambda x, y: x + y, i)
b = fun(eval(input("输入列表:")))
print(b)