2019.11.04

 

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、如果猜对了,就直接退出

 

2019.11.04

 

 

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)

 

 

 

上一篇:day04


下一篇:02-jquery的选择器