Python学习之旅-13

Python基础

小程序设计

  这里我使用的是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);
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值