Navbar menu
(Move to ...)
Home
Python
HTML
JavaScript
Quiz
AS400 / IBM iSeries
Contact Us
▼
For loop - Python programs
Display sum of 1 to 10 number by using for loop
Code Snippet:
#Display sum 1 to 10 number by using for loop n=10 ans=0 for i in range(1,n+1): ans+=i print("Sum of 1 to 10 number using for loop:",ans)
Copy
Display sum 1 to 10 number by using for loop
Output:
Output - display sum 1 to 10 number
Program to search a value in a list
#To search a value in a list using for loop search = input("Enter your input to search in list:") source=['1','2','three','4','five'] count=0 for i in source: if i == search: print(search,'is present in source list') count+=1 if count == 0: print(search,'is not present in source list')
Copy
Search value in a list using for loop
Output:
Output - search value in a list
Method 2:
We can code this logic using simple if-else conditions also.
Search value in a list using if-else
No comments:
Post a Comment
‹
›
Home
View web version
No comments:
Post a Comment