码迷,mamicode.com
首页 > 其他好文 > 详细

2019.11.04

时间:2019-11-04 21:31:28      阅读:89      评论:0      收藏:0      [点我收藏+]

标签:style   ase   +=   tag   for   end   技术   mic   int   

 

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

count = 0

while count < 10:
count += 1
if count == 7:
continue


print(count)

运行结果为:1 2 3 4 5 6 8 9 10 

 

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

a = 0

for i in range(1,101):
a = a+i

print(a)

运行结果为:5050

 

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

 

n = 1
while n<101:
if n % 2 == 0:
n = n + 1
else:
print(n)
n = n + 1

 

 

 

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

n = 1
while n<101:
if n % 2 == 0:
print(n,end=" ")
n = n + 1
else:
n = n + 1

 

 

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

num = 0
for i in range(100):
if i % 2 == 0:
num = num - i
else:
num = num + i

print(num)

 

6、猜年龄游戏

、、、python

要求:

1、允许用户最多尝试3次

2、每尝试3次后,如果还没猜对,就问用户是否还想继续玩,如果回答Y或y,就继续让其猜3次,以此往复,如果回答N或你,就退出程序

3、如果猜对了,就直接退出

 

技术图片

 

 

age = 10
count = 0
numb = 0
tag = True
Y = [‘Y‘,‘y‘]
N = [‘N‘,‘n‘]
while tag:
count = 0
while count<3:
num_inp = input("please give your age>>:")
num_inp = int(num_inp)
if num_inp == age:
print("猜对了")
tag = False
break
else:
print("猜错了")
count+=1
if count == 3:
ord = input ("continue? Y/N>>:")
if ord in Y:
tag = True
elif ord in N:
tag = False

 

7、运用所学知识,打印以下图案:

、、、python

       *

      ***

     *****

    *******

   *********

、、、

 

print("‘

       *

      ***

     *****

    *******

   *********

‘‘‘)

 

list = ["    *","   ***","  *****"," *******","*********"]

for i in list:
print(i)

 

 

 

2019.11.04

标签:style   ase   +=   tag   for   end   技术   mic   int   

原文地址:https://www.cnblogs.com/medigrat/p/11792741.html

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