1. The while loop output 1234568910
Code:
count=0
while count<10:
count += 1
if count ==7:
continue
print(count,end=" ")
effect:
2. All numbers 1-100 and seek
Code:
s=0
i=0
while i<=100:
s+=i
i+=1
print(s)
effect:
3. The outputs of all the odd-numbered 1-100
Code:
i=0
while i<100:
i = i + 1
if i%2!=0:
print(i,end=" ")
effect:
4. Output all even within 1-100
Code:
i=0
while i<100:
i = i + 1
if i%2==0:
print(i,end=" ")
effect:
The request and all numbers 1-2 + 3-4 + 5 ... 99
Code:
s=0
i=1
while i<=99:
r=pow(-1,i+1)
s+=r*i
i+=1
print(s)
effect:
6. User Login (three chances to retry)
Code:
old_name='king'
old_password='123'
count=0
while count<3:
name = input("请输入你的姓名:")
password = input("请输入你的密码:")
if name==old_name and password==old_password:
print("登录成功!")
break
else:
print("请输入正确的密码或姓名!")
count+=1
effect:
7: Guess the age of the game
Code:
old_age="20"
count=0
while count<3:
age = input("请输入你的猜测的年龄:")
if age==old_age:
print("太棒了!猜测正确!")
break
else:
print("好可惜!猜错了!")
count+=1
effect:
8: Guess the age of an upgraded version of the game (OPTIONAL)
Code:
old_age="20"
count=0
while count<3:
age = input("请输入你的猜测的年龄:")
if age==old_age:
print("太棒了!猜测正确!")
break
else:
print("好可惜!猜错了!")
count+=1
if count==3:
choice=input("你还想继续猜吗?y/n")
if choice=="y":
count=0
continue
else:
break
effect:
9.for print circulation 99 multiplication table
Code:
for i in range(1,10):
for j in range(1,i+1):
print(f'{j}*{i}={(i*j): ^2}',end=' ')
print("")
effect:
10.for circulation print pyramid
Code:
for i in range(1,6):
print(f'{"*"*(2*i-1): ^9}')
effect: