•
score=int(input("Enter the score"))
if score>90 : grade ="A“
elif score>80 : grade="B“
elif score >70: grade="C“
elif score>60 : grade="D“
elif score>50:grade="E“
else : score = "F“
print ('nGrade for',score,'is : ',grade)
Output
Enter the score 85
Grade for 85 is : B
•
In Python, break and continue statements can alter the flow of a
normal loop
The continue statement is used to skip the rest of the code inside a loop
for the current iteration only. Loop does not terminate but continues on
with the next iteration
• Loops iterate over a block of code until the test expression is false
• but sometimes we wish to terminate the current iteration
• or even the whole loop without checking test expression.
The break statement terminates the loop containing it. Control of the
program flows to the statement immediately after the body of the
loop.
•
•
The break statement terminates the loop containing it. Control of
the program flows to the statement immediately after the body of
the loop.
# Use of break statement inside the loop
for val in "string":
if val == "i":
break
print(val)
print("The end")
Output
s
t
r
The end
•
The continue statement is used to skip the rest
of the code inside a loop for the current
iteration only. Loop does not terminate but
continues on with the next iteration.
The continue statement can be used to skip
certain portion of the code inside a loop for
the current iteration only
•
•
The continue statement is used to skip the rest of the code inside a
loop for the current iteration only. Loop does not terminate but
continues on with the next iteration.
# continue statement inside loops
for val in "string":
if val == "i":
continue
print(val)
print("The end")
Output
s
t
r
n
g
The end
•
There is a typical structure to print any pattern: Outer loop
represents rows and the inner loop represents
Accept the number of rows from a user using input() function or
decide the size of a pattern.
Iterate the number of rows using outer for loop and range() function
Next, the inner loop or nested for loop to handle the number of
columns. Inner loop iteration depends on the values of the outer
loop.
Print start, number, asterisk, Pyramid, and diamond pattern using the
print() function.
Add a new line after each row, i.e. after each iteration of outer for
loop so you can display pattern appropriately.
•
rows = 6
for num in range(rows):
for i in range(num):
print(num, end=" ") # print number
# line after each row to display pattern correctly
print(" ")
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
•
Python programming
Try to print different patterns using python
Thankyou
Python programming
Then program should accept
n numbers
Write a python program to accept n
Rewrite using for loop and
Upload Program on
Lms.ihrdcasvattamkulam.ac.in
Then print the largest and second largest of
n numbers
PyClassDay13.pptx

PyClassDay13.pptx

  • 2.
    • score=int(input("Enter the score")) ifscore>90 : grade ="A“ elif score>80 : grade="B“ elif score >70: grade="C“ elif score>60 : grade="D“ elif score>50:grade="E“ else : score = "F“ print ('nGrade for',score,'is : ',grade) Output Enter the score 85 Grade for 85 is : B
  • 3.
    • In Python, breakand continue statements can alter the flow of a normal loop The continue statement is used to skip the rest of the code inside a loop for the current iteration only. Loop does not terminate but continues on with the next iteration • Loops iterate over a block of code until the test expression is false • but sometimes we wish to terminate the current iteration • or even the whole loop without checking test expression. The break statement terminates the loop containing it. Control of the program flows to the statement immediately after the body of the loop.
  • 4.
  • 5.
    • The break statementterminates the loop containing it. Control of the program flows to the statement immediately after the body of the loop. # Use of break statement inside the loop for val in "string": if val == "i": break print(val) print("The end") Output s t r The end
  • 6.
    • The continue statementis used to skip the rest of the code inside a loop for the current iteration only. Loop does not terminate but continues on with the next iteration. The continue statement can be used to skip certain portion of the code inside a loop for the current iteration only
  • 7.
  • 8.
    • The continue statementis used to skip the rest of the code inside a loop for the current iteration only. Loop does not terminate but continues on with the next iteration. # continue statement inside loops for val in "string": if val == "i": continue print(val) print("The end") Output s t r n g The end
  • 9.
    • There is atypical structure to print any pattern: Outer loop represents rows and the inner loop represents Accept the number of rows from a user using input() function or decide the size of a pattern. Iterate the number of rows using outer for loop and range() function Next, the inner loop or nested for loop to handle the number of columns. Inner loop iteration depends on the values of the outer loop. Print start, number, asterisk, Pyramid, and diamond pattern using the print() function. Add a new line after each row, i.e. after each iteration of outer for loop so you can display pattern appropriately.
  • 10.
    • rows = 6 fornum in range(rows): for i in range(num): print(num, end=" ") # print number # line after each row to display pattern correctly print(" ") 1 2 2 3 3 3 4 4 4 4 5 5 5 5 5
  • 11.
  • 12.
    Python programming Try toprint different patterns using python
  • 13.
  • 14.
    Python programming Then programshould accept n numbers Write a python program to accept n Rewrite using for loop and Upload Program on Lms.ihrdcasvattamkulam.ac.in Then print the largest and second largest of n numbers