python語法之流程控制

#一、使用while循環輸出1 2 3 4 5 6  8 9 10
# count = 0
# while count < 10:
#     count += 1
#     if count == 7:
#         continue
#     print(count)


#二、求1-100的全部數的和
# sum = 0
# for i in range(1, 101):
#     sum += i
#     print(sum)


#三、輸出1-100內的全部奇數
# for i in range(1, 101, 2):
#     print(i)


#四、輸出1-100內的全部偶數
# for i in range(2, 101, 2):
#         print(i)


#五、求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}")
#
#
# #六、猜年齡遊戲
# 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



#七、運用所學知識,打印如下圖案
#     *
#    ***
#   *****
#  *******
# *********

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))
相關文章
相關標籤/搜索