一:循环语句
1.计算1+2+3+4....+100
count = 1 sum = 0 while count <= 100: sum +=count count +=1 print("sum =" ,sum)
2.计算1+2-3+4..+99
count = 1 sum = 0 # while count <= 100: # sum +=count # count +=1 # # print("sum =" ,sum) while count < 100 : if count % 2 == 0: sum = sum - count else: sum = sum + count count += 1 print(sum)
3.输出一个自我介绍
name = input("请输入你的名字:") age = int(input("请输入你的年龄:")) job = input("请输入你的工作:") msg = '''------ info in %s------ Name : %s Age : %d Job : %s --------------- end ------------''' %(name,name,age,job) print(msg)
---小米