#1、使用while循环输出1 2 3 4 5 6 8 9 10 # count = 0 # while count < 10: # count += 1 # if count == 7: # continue # print(count) #2、求1-100的所有数的和 # sum = 0 # for i in range(1, 101): # sum += i # print(sum) #3、输出1-100内的所有奇数 # for i in range(1, 101, 2): # print(i) #4、输出1-100内的所有偶数 # for i in range(2, 101, 2): # print(i) #5、求1-2+3-4+5...99的所有数的和 # sum = 0 # for i in range(100): # if i % 2 != 0: # sum += i # else: # sum -= i # print(f"1-2+3-4+5…+99的所有数的和:{sum}") # # # #6、猜年龄游戏 # age = '18' # tag = True # count = 0 # while tag: # guess_age = input('请输入年龄:').strip() # # guess_age = int(guess_age) # if guess_age == age: # print('猜对了') # break # else: # print('猜错了') # count += 1 # if count % 3 == 0: # answer = input('继续猜请输入Y或y,退出请输入N或n:').strip() # if answer not in ['Y', 'y']: # tag = False #7、运用所学知识,打印以下图案 # * # *** # ***** # ******* # ********* for i in range(1, 6): print(' '*(5-i) + '*'*(2*i-1) + ' '*(5-i))
for i in range(1, 10, 2):
print(("*" * i).center(9))