码迷,mamicode.com
首页 > 编程语言 > 详细

python学习第一天

时间:2018-05-04 17:09:10      阅读:170      评论:0      收藏:0      [点我收藏+]

标签:python

#使用while循环输入1 2 3 4 5 6 8 9 10 num = 1 while num <=11: if num == 7 or num == 11: num += 1 continue print(num) num += 1 #输出 1-100 内的所有奇数 num = 1 while num <= 100: if num % 2 == 1: print(num) num += 1 #输出 1-100 内的所有偶数 num = 1 while num <= 100: if num %2 == 0: print(num) num += 1 #求1-2+3-4+5 ... 99的所有数的和 a = ‘‘ b = 0 for i in range(1,100): a += str(i) if i % 2 == 0: a += ‘+‘ b -= i else: a += ‘-‘ b += i print(‘输出: \r\n %s \r\n计算结果:\r\n %s‘ % (a.rstrip(‘-‘),b)) 用户登陆(三次机会重试) name="LJS" pswd="123" i=1 while i < 4: input_name = input("Username:") input_pswd = input("Password:") if input_name == name and input_pswd == pswd: print("Welcome to my program!") break else: print("The user name or password you entered is incorrect. Please enter again.") i += 1 continue

python学习第一天

标签:python

原文地址:http://blog.51cto.com/shengge520/2112752

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!