0. How many times will the following loop print "I love FISHC"?for I in Range (0, 2): print (' I love FISHC ') Print 5 times, range (Start,stop, interval)1. How many times will the following loop print "I love FISHC"? For i in 5: print (' I love FISHC ') error, invalid syntax, 5 is integral type, cannot be used as the iterated algebraic value 2. Review the role of break and continue in the cycle?
A: Break terminates the cycle when the condition is set and ends the program. Continue terminates the loop back to the start position of the loop body when the condition is set, and executes continue the following statement if the condition is false. 3. What are the numbers generated by range (10)? Answer: 0,1,2,3,4,5,6,7,8,9 4. Under what circumstances should we make the cycle always true? While Ture: The loop body is also used for game implementations because the game needs to receive user input whenever it is running, so use always to make sure the game is "online". The same is true of the operating system, always on standby, the operating system is always real this cycle is called the message loop. In addition, the client/server system of many communication servers is also working through this principle.
So forever is "true" although is "the cycle of death", but not necessarily bad, besides, we can always use break to jump out of the loop! 5. "Learn to improve the efficiency of your code" What do you think of the following code efficiency? Is there a way to drastically improve (still use while)?
i = 0
string = ' ilovefishc.com '
While I < Len (string):
print (i)
i + = 1
For:
I =0
string = ' ilovefishc.com '
Length =len (String)
While i< length:
Print (i)
I +=1
Do it:
0. Design a verification user password program, the user only three times the opportunity to enter the error, but if the user input content contains "*" is not counted.
Write their own ci==0 when there is a problem and no solution
Mima= ' 123AAA '
Ci=3
Temp =input (' Shurumima: ')
While CI:
If Temp==mima:
Print (' Zhengque ')
Break
Elif ' * ' in temp:
Temp=input (' Buenngbaoh *,cishu%s,chongxinshuru '%ci)
Elif ci ==0:
Print (' Zhanghaoshuoding,qing10fenzhonghou ')
Else
CI-=1
Temp=input (' Cishushaoleyici,%s,chongxinshuru '%ci)
Small Turtle Code:
Count = 3password = ' fishc.com ' while count: passwd = input (' Please enter password: ') if passwd = = password: print (' Password is correct, Enter program ... ') Break elif ' * ' in passwd: print (' Password cannot contain ' * ')! You also have ', count, ' Chance! ', end= ') continue else: print (' Password input error! You also have ', count-1, ' Chance! ', end= ') count-= 1
1. Write a program that asks for the number of daffodils between 100~999.
If a 3-digit number is equal to the cubic sum of its members, it is called the number of daffodils. For example: 153 = 1^3 + 5^3 + 3^3, so 153 is a number of daffodils.
For a in range (100,1000):
I=a
i== (i//100) **3+ ((I//10)%10) **3+ (i%10) **3
If I==a:
Print (i)
Else
Print (")
Small Turtle Code:
For I in range (+): sum = 0 temp = i while temp: sum = sum + (temp%10) * * 3 temp//= Notice here to use the floor except for Oh ~ if sum = = I: print (i)
2. Tri-Color ball problem
There are three colors of red, yellow, blue ball, of which the red ball 3, Yellow ball 3, blue Ball 6. The 12 balls are mixed in a box, and any 8 balls are drawn from it, and the various color combinations of the ball are programmed and calculated.
Blue must have 2-6 red 0-3 yellow 0-3
Print (' Red\tyellow\tblue ')
For red in range (0, 4):
For yellow in range (0, 4):
For blue in range (2, 7):
If red + yellow + blue = = 8:
Print (red, ' \ t ', yellow, ' \ t ', blue)
Little Turtle Python after the eighth lecture exercise