Skip to content

Loops for beginner #2658

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions loops.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# 2 loops

# for loop:

"""
Syntax..
-> "range" : starts with 0.
-> The space after the space is called as identiation, python generally identifies the block of code with the help of indentation,
indentation is generally 4 spaces / 1 tab space..


for <variable> in range(<enter the range>):
statements you want to execute

for <varaible> in <list name>:
print(<variable>)
To print the list / or any iterator items

"""

# 1. for with range...
for i in range(3):
print("Hello... with range")
# prints Hello 3 times..

# 2.for with list

l1=[1,2,3,78,98,56,52]
for i in l1:
print("list items",i)
# prints list items one by one....

for i in "ABC":
print(i)

# while loop:
i=0
while i<=5:
print("hello.. with while")
i+=1
13 changes: 13 additions & 0 deletions saving_input_into_list.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
ran= int(input("Enter the range of elements you want to store / insert "))
l1=[]
for i in range(ran):
l1.append(input("Enter here "))

print(l1)


"""
program first asks the user how many values they want to enter. Then, using a loop, it lets the user enter that many values one by one.
Each entered value is saved into a list called l1. Once all the values are entered, the program prints the complete list, showing
everything the user typed. It's a beginner-friendly way to learn how to collect multiple inputs and store them for later use.
"""
Loading