• python基础作业练习-20171214


    1、使用while循环输入 1 2 3 4 5 6     8 9 10

    count = 1 
    
    while count <= 10:
        if count == 7:
            count = count + 1
            continue
        print(count)
        count = count + 1
    

      

    2、求1-100的所有数的和

    count = 1 
    sum = 0
    
    while count <= 100:
    	sum = sum + count
    	count = count + 1 
    
    print(sum)
    

    3、输出 1-100 内的所有奇数

    count = 1 
    
    while count <= 100:
    	if count % 2 ==1:
    		print(count)
    		count = count + 1
    	count = count + 1
    

    4、输出 1-100 内的所有偶数

    count = 1
    
    while count <= 100:
    	if count % 2 ==0:
    		print(count)
    		count = count + 1
    	count = count + 1
    

    5、求1-2+3-4+5 ... 99的所有数的和

    count = 1 
    sum = 0 
    
    while count <= 99:
    	if count ==1:
    		sum = count
    		count = count + 1
    		continue
    	else:
    		if count % 2 ==1:
    			sum = sum + count
    			count = count + 1
    		else:
    			sum = sum - count
    			count = count + 1
    print(sum)
    

    6、用户登陆(三次机会重试)

    count = 1
    sum = 0
    
    while count <= 3:
    	username = input('请输入用户名:')
    	password = input('请输入用户密码:')
    	if username == 'Jason' and password == '123':
    		print('登录成功,欢迎“Jason”回来!')
    		break
    	else:
    		sum = 3 - count
    		print('用户名或密码错误,请重新输入,目前还剩余'+str(sum)+'机会!')
    		count = count + 1
    

     

  • 相关阅读:
    Datasource Server returns invalid timezone问题
    springboot之异常处理
    maven的安装配置
    Javajdk的安装
    jdbc连接mysql数据库 (idea)
    关于MySQL数据库的卸载
    python3.6.8的安装及初步使用
    计算机基础及编程语言的简单了解
    git、码云的使用
    粘滞位权限
  • 原文地址:https://www.cnblogs.com/jason-lv/p/8038995.html
Copyright © 2020-2023  润新知