DEV Community 👩‍💻👨‍💻

Sayan Mandal
Sayan Mandal

Posted on

Day 5 of Python Pro Bootcamp 👨‍💻

Day 5

Course Outline:

Loops:

for loop is used for iteration over a list(some other data structures)

sports = ["Basketball", "Tennis", "Baseball", "Volleyball"]

# this is a for loop
for sport in sports:

    # this will print each strings of the sports list indvidually
    print(sport)
Enter fullscreen mode Exit fullscreen mode

Output:

Basketball
Tennis
Baseball
Volleyball
Enter fullscreen mode Exit fullscreen mode

In two coding challeneges avg_height.py and student_score.py we saw how with the for loop built-in functions like sum, len and max can be executable.

for loops and the range() function

range function gives sequence of numbers. By default range function starts from 0 and 1 increments.

for number in range(5):
    print(number)
Enter fullscreen mode Exit fullscreen mode

Output:

0
1
2
3
4
Enter fullscreen mode Exit fullscreen mode

range function with multiple arguments

for number in range(5, 101, 10): # range(start, stop, step)
    print(number)
Enter fullscreen mode Exit fullscreen mode

Output:

5
15
25
35
45
55
65
75
85
95
Enter fullscreen mode Exit fullscreen mode

Today has been the a little difficult one so far using the for loop and range function. Learnt how some built-in function works. Used the random library on multiple exercises and got more familiar with random.choice() and random.shuffle()

Project: Password Generator

Description: It generates a random password consisting letters, number, and symbols.

My Solution: password_generator.py

4 Hours of Ambient Study Music To Concentrate

P.S. It's fun to watch football while coding!

Top comments (0)

We want your help! Become a Tag Moderator.
Check out this survey and help us moderate our community by becoming a tag moderator here at DEV.