#100DaysofCode — Day (5)
Full disclosure - Each #100DaysofCode project I’m taking is part of the wonderful “100 Days of Code: Tye Complete Python Pro Bootcamp for 2022” course offered by the App Brewery found on udemy here:
In no shape or form am I being sponsored or rewarded by promoting them. I also want to stress that while these are not my ideas to come up with a different challenge everyday, the code that I’m sharing is my own and not copy pasted from their solutions.
Today’s section was on
for loops, which is used to iterate over a sequence.
fruits = ["Apple", "Peach", "Pear"]
for fruit in fruits:
print(fruit + " Pie")
The code above, when run, will output the each item in the list, followed by that item and the word
Do pear pies even exist? I feel like I’ve never even heard of those.
for loops, we created two tools: One that calculates average height (in centimeters) and one that calculates the highest score out of a list.
The penultimate project for the day was a password generator.
The password generator asks the user to input how many letters (lowercase and uppercase), numbers, and symbols they want, and then generates a password containing those values in a random order using the
I thought using the
in range() function was interesting for a few reasons. It was initially throwing me for a loop (get it) when I was trying to pass in my variables there, as I thought that’s all I needed to do. After trying a few things, I realized I had to input
1 for the first argument and use my variable for the second. I believe this is due to 1 being the minimum of the range. I also thought it was interesting that we had to add
+ 1 to the argument at the end to actually include the number of characters the user wanted. For instance, without that
+ 1 if a user wanted 4 letters, then only 3 would end up being used.
I sound like a broken record, but I’d like to revisit this again and ask the user if they’d like another password after the first one is displayed. I’d say this password generator is fairly secure, but use at your own risk!