python新手程序_【python学习】新手基础程序练习(一)

首先得先编一下程序员必须编的程序——Hello World……(这应该是程序员情结。。。)

1 #coding=utf-8

2 #Version:python3.7.0

3 #Tools:Pycharm 2017.3.2

4 _date_ = '2018/12/30 12:26'

5 _author_ = 'Colby'

6 print('Hello World!')

一、输出1,2,3,4,5,6,8,9,10

1 #coding=utf-8

2 #Version:python3.7.0

3 #Tools:Pycharm 2017.3.2

4 _date_ = '2018/12/30 7:49'

5 _author_ = 'Colby'

6 count =07 num = 1

8 while count < 10:9 if num == 7:10 pass

11 else:12 print(num)13 num += 1

14 count += 1

二、求1~100的和

1 #coding=utf-8

2 #Version:python3.7.0

3 #Tools:Pycharm 2017.3.2

4 _date_ = '2018/12/30 7:52'

5 _author_ = 'Colby'

6 num = 1

7 count =08 while num < 101:9 count = count +num10 num += 1

11 print(count)

三、求1-2+3-4+5...+99的值

1 #coding=utf-8

2 #Version:python3.7.0

3 #Tools:Pycharm 2017.3.2

4 _date_ = '2018/12/30 7:54'

5 _author_ = 'Colby'

6 num = 1

7 count =08 while num < 100:9 temp = num % 2

10 if temp ==0:11 count = count -num12 else:13 count =count +num14 num += 1

15 print(count)

四、输出1~100所有的奇数

1 #coding=utf-8

2 #Version:python3.7.0

3 #Tools:Pycharm 2017.3.2

4 _date_ = '2018/12/30 7:58'

5 _author_ = 'Colby'

6 num = 1

7 while num < 101:8 temp = num % 2

9 if temp ==0:10 pass

11 else:12 print(num)13 num += 1

五、输出1~100所有的偶数

1 #coding=utf-8

2 #Version:python3.7.0

3 #Tools:Pycharm 2017.3.2

4 _date_ = '2018/12/30 8:00'

5 _author_ = 'Colby'

6 num = 1

7 while num < 101:8 temp = num % 2

9 if temp == 1:10 pass

11 else:12 print(num)13 num += 1

六、用户登录(三次登录机会,用户名和密码自己设定)

1 #coding=utf-8

2 #Version:python3.7.0

3 #Tools:Pycharm 2017.3.2

4 _date_ = '2018/12/30 8:01'

5 _author_ = 'Colby'

6 #import os

7 num = 1

8 while num < 4:9 temp = 3 -num10 user_id = input("请输入用户名:")11 user_passwd = input("请输入密码:")12 if user_id == "zjx" and user_passwd == "123456":13 print("登录成功!")14 break

15 else:16 if temp >0:17 print("登录错误!您还可以输入%d次!"%(temp))18 else:19 print("已被锁定!请30秒后重新登录!")20 num += 1

21 #os.system('cls')

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值