一、用户交互.input
变量将运算的中间结果暂存在内存,以便后续程序调用 一、使用while循环输入 1 2 3 4 5 6 7 8 9 10 count = 1 while count < 11: if count == 7: count += 1 continue print(count) count +=1 else:print("end") 二、求1-100的所有数的和 count = 1 sum = 0 while count < 101: sum = sum + count count += 1 print(sum) 三、输出1-100内的所有奇数 count = 1 while count < 101: if count %2 == 1: print(count) count += 1 print("end") 四、输出1-100内所有偶数 count = 1 while count < 101: if count %2 ==0: print(count) count += 1 print("end") 五、求1-2+3-4+5....99的所有数的和 #方法一 sum = 0 count = 1 while count < 100: if count %2 == 0: sum = sum - count print(sum) elif count %2 == 1: sum = count + sum print(sum) count += 1 print(sum) #方法二 sum1 = 0 sum2 = 0 count = 1 while count < 100: if count %2 == 1: sum1 = sum1 + count else: sum2 = sum2 + count count += 1 print(sum1 - sum2) 六、用户登陆(三次机会重试) count = 1 while count < 4: name = input("please input your name=") password = input("please input your password=") if name == "xue" and password == "123": print("登陆成功") break else: print("登陆失败") count += 1 七、第六题基础增加,字符串拼接 count = 3 while count > 0: name = input("please input your name=") password = input("please input your password=") if name == "xue" and password == "123": print("登陆成功") break else: count -= 1 if count == 0: print("登陆失败") else: print("还剩"+ str(count) + "次") #ps:字符串拼接,相乘。可相加相乘知识点 name = input("please your name ") age = input("please your age") print("你的名字" + name , "你的年纪" + age) i = "name" print(name * 8) ”“”
ps:python3 input
python2 raw_input
二、if语句.
三、while.
while 条件:
结果
结束循环:
1,改变条件.
2,break
break continue
break:在循环当中,遇到break,直接退出
continue:结束本次循环,继续下一次循环.