2019.07.17 learning work (programming)

day04 HomeWork

1. The while loop output 1234568910

count = 0
while count < 10:

    if count == 6:
        count += 1
        continue
    count += 1
    print(count,end=' ')

2. All numbers 1-100 and seek

sum=0
count=0
while count<100:
    count +=1
    sum+=count
print(sum)

3. The outputs of all the odd-numbered 1-100

count=1
while count<100:
    if count % 2==1:
     print(count,end=' ')
    count+=1

4. Output all even within 1-100

count=1
while count<=100:
    if count % 2==0:
     print(count,end=' ')
    count+=1

The request and all numbers 1-2 + 3-4 + 5 ... 99

sum=0
for i in range(1,100):
    if i%2==0:
        sum -=i
    else:
        sum+=i
print(sum)

6. User Login (three chances to retry)

id='1608210104'
pw='123456'
for i in range(3):
    id1 = input('Please your enter id:')
    pw1 = input('Please your enter password(您只有三次机会):')
    if id1==id and pw1==pw:
        print('you enter is True(你已登录成功)')
    else:
        print('you enter is False')
print('三次机会已用完')

7. guess the age of the game

age='18'
for i in range(3):
    age1 = input('Please your enter age:')
    if age1==age:
        print("your answer is very True")
        break
    else:
      continue

8. guess the age of an upgraded version of the game (OPTIONAL)

After required to allow users to try up to three times per attempt # 3, if you have not guessed, asked whether the user would like to continue playing, if the answer Y or y, then allowed to continue to guess three times, this back and forth, if the answer N or n, how to exit the program # guessed it, on exit

i=0
age=18
while i!=3 :
    age = input("Please your enter age:")
    if age== 18:
        print("your answer is True")
        break
    i += 1  # 计数器就加1

    if i == 3:  # 次数
        ret = input("是否还想玩(Y/N):")
        if ret == "Y" or ret =="y":
            i = 0;

9.for print circulation 99 multiplication table

for i in range(1,10):
    for j in range(1,i+1):
        print(f'{i}*{j}={i*j}',end='  ')
    print()

10.for circulation print pyramid: as follows

for i in range(1,6):
        print(f"{'*'*(i+i-1): ^9}")

Guess you like

Origin www.cnblogs.com/xichenHome/p/11202548.html