⭐第六题:代码
1. for i in range(1, 10): 2. for j in range(1, i+1): 3. print(f'{j}x{i}={i*j} ', end='') 4. print()
⭐第七题:代码
number = int(input('请输入数字...')) row = 1 while row <= number: col = 1 while col <= row: print('◻',end=' ') col += 1 # col = col + 1 pass print() # 换行 row += 1
⭐第八题:代码
row = 1 while row <= 10: j = 1 while j <= 10-row: print(' ',end=' ') # 前面9行为空格 j += 1 # 根据j的表达式的值为真还是为假 pass # 控制打印符号 k = 1 while k <= 2*row-1: print('◻',end='') k += 1 # 执行打印符号k就+1,注意如果这里是打印三个◻,它并不是直接打印◻,而是每次打印都要回到while循环,这样就是每次打印◻,就是加一次k pass print() # 换行 row += 1 # 执行完之后row+1
⭐第九题:代码
import random # 生成随机值 person = int(input('请输入猜拳[0石头,1剪刀,2布]:...')) computer = random.randint(0,2) # rand();功能随机生成数字 0~32767之间 # 打印三种情况 # 人 赢了 if person == 0 and computer == 1: print('老铁666') pass elif person == 1 and computer == 2: print('老铁666') pass elif person == 2 and computer == 0: pass print('老铁666') pass # 平手 elif person == computer: print('下次一定') pass # 输了 else: print('不服再来')
⭐第十题:代码
tmp = 0 for i in range(1,101): tmp = tmp + i print("sum = %d" % tmp)