这里我使用的是eclipse来写代码,因为在练习基础知识的时候还可以顺带着练习一下java编程,毕竟程序语言的编程思想都是想通的 python篇
def work1(): it=0 while(it<10): it+=1 if(it==7): continue print(it) def work2(): it=0 sum=0 while(it<100): it+=1 sum+=it print(sum) def work3(): it=0 while(it<100): it+=1 if(it%2==1): print(it) def work4(): it=0 while(it<100): it+=1 if(it%2==0): print(it) def work5(): sum=0 it=0 while(it<99): it+=1 if(it%2==0): sum+=it else: sum-=it print(sum) def work6(): count=0 while(True): username=input('请输入您的用户名 ') password=input('请输入你的密码 ') if(username=='zhangsan' and password=='123456'): print('登陆成功') break else: count+=1 if(count>=3): print('登陆失败,三次机会已用完,请明天再试') break print('登陆失败,请重新尝试(剩余机会-->%d次)'% (3-count)) if __name__=='__main__': work1()#使用while循环输出1 2 3 4 5 6 8 9 10 print('===========') work2()#求1-100的所有数的和 print('===========') work3()#输出 1-100 内的所有奇数 print('===========') work4()#输出 1-100 内的所有偶数 print('===========') work5()#求1-2+3-4+5 ... 99的所有数的和 print('===========') work6()#用户登陆(三次机会重试)Java篇
public class Work_1 { public static void main(String[] args) { // TODO Auto-generated method stub work1();//使用while循环输出1 2 3 4 5 6 8 9 10 System.out.println("========"); work2();//求1-100的所有数的和 System.out.println("========"); work3();//输出 1-100 内的所有奇数 System.out.println("========"); work4();//输出 1-100 内的所有偶数 System.out.println("========"); work5();//求1-2+3-4+5 ... 99的所有数的和 } public static void work1(){ int it = 0; while (it<10) { it++; if (it==7) { continue; } System.out.println(it); } } public static void work2(){ int sum = 0; int it = 0; while (it<100) { it++; sum+=it; } System.out.println(sum); } public static void work3(){ int it = 0; while (it<100) { it++; if (it%2==1) { System.out.println(it); } } } public static void work4(){ int it = 0; while (it<100) { it++; if (it%2==0) { System.out.println(it); } } } public static void work5(){ int sum = 0; int it = 0; while (it<99) { it++; if (it%2==0) { sum+=it; }else { sum-=it; } } System.out.println(sum); } }