Small turtle Chapter VI summary and reflection after-school title

Basic question:
0. Python's floor division now use "//" to achieve that 3.0 // 2.0 You will show visually what it?
Because pyhon floating-point computer system will automatically remove something after the decimal point to note here

2. Do not use IDLE, you can easily tell the value 5 ** -2 it?
A: 0.04

Note that the left lower and right high power operation principle
4. Say the speed of the fastest answer: Not. 1 or 0. 1 and or or. 5. 4. 3 and or and. 6. 7. 8 and. 9 and ,

Note priority! ! ! ! not> and> or
pay attention to short-circuit logic! ! ! ! ! 3and4 = 4 3or4 = 3 0or4 = 4
so the first and changed to a combination of: 0 or 0 or 4 or 6 or 9 = 4

The programming problem
0. Please write a program to print out all the odd-numbered from 0 to 100.

temp = input ('输入1-100一个数从而得知当中所有的奇数;')
number = int(temp)
i=1
if number % 2 == 0:
    number -= 1
while i != (number+2):
    print (i)
    i += 2
或者(网上答案)
i = 0
while i <= 100:
    if i % 2 !=0:
        print(i)
        i += 1
    else:
        i +=1

2. Einstein had been out such an interesting math problem: there is a long ladder, step 2 if each step, the last remaining step 1; 3 order if each step, the last remaining second-order; if the order of 5 per step , the last remaining step 4; 6 if the order of each step, the last remaining stage 5; 7 only on the order of each step, just a final order is not left. Title: Please programming to solve the ladder at least the number of bands?

求助网上的答案:
x = 7
i = 1
flag = 0

while i <= 100:
    if (x%2 == 1) and (x%3 == 2) and (x%5 == 4) and (x%6==5):
        flag = 1
    else:
        x = 7 * (i+1)
    i += 1
#注意这里i += 1 与if else并列,而不是在else里面。原因是若在else里面,则当为正确答案的时候,i不会改变,于是一直while循环,从而不能继续后面的if操作。
if flag == 1:
    print('阶梯数是:', x)
else:
    print('在程序限定的范围内找不到答案!')

Summary: 1 priority, short-circuit logic
2. Note logic. It began to get the first reaction is often a question of logic programming. As Einstein that question, the first reaction is to get 2-based answers, and answers to the same 7 for answers. Note that at the beginning of the initial assignment is written back logic pave
3. Note that frame, i + = 1 different meanings in different places expression, attention logic diagram Contacts

Published 17 original articles · won praise 1 · views 367

Guess you like

Origin blog.csdn.net/cccccccaaaaaaaaa/article/details/105178795