Skip to content
← Back to Community
Learn to code Python! Part 3: For and While!
Profile icon

Welcome back to Part 3 of my Python tutorial here on replit. Yes, this is the third one today but school is boring so here I am doing this. In the last tutorial we learnt about if, elif, and else. These are pretty much the most important thing in python ever.

So head on over to your code and look at elif func_select == 2:. We are going to be deleting accounts so we need to get information from the user about what account they want deleted. So first add this code inside that elif statement.

accDelete = input("account: ")

Next we are going to iterate through the list accounts. What is iterating says the padawan at the front, well iterating is looping. If I was to iterate through a string "Hello World", then I would be looping through each character of that string once. We can do this with a for loop, I will show you another type of loop in a second.

For Loop

A for loop works by iterating through each character in a string, or each item in a list. So what we want to do is iterate through each item in a list to find the specific account we will be deleting. So copy this code into the file.

for items in accounts: if items == accDelete: accounts.remove(items)

So this is a for loop, it iterates through the thing it's being told to which in this case is accounts. You see items up there? Well items is a variable which is equal to the item or character that you are currently iterating through. So if items is equal to the account the person wants to delete then, remove items.

So, what if they capitalise the account wrong? Good question, we need to go up to if func_select == 1: and change something in here. So we can turn the account into all lowercase letters so that it is easier to find the correct account.

accCreateLow = accCreate.lower()

This turns all the characters into lowercase letters, we can change lower to upper to make them uppercase. Now do the same in elif func_select == 2:, then change the for loop accordingly, I will let you do that.

When testing this, make sure to add at 1 least value to the accounts and balance list because when adding an account the code itself won't update

And you are now done the account deletion! Congrats!

While Loop

Here is that other loop I was talking about. It is called a while loop, it does the same thing over and over until the condition is false.

while condition: body

So it's pretty simple, we can make it say hello world 5 times.

i = 0 while i <= 6: print("Hello World") i = i + 1

This will print "Hello World" 5 times. Now <= means less than or equal to, you can do the same with >. See i = i + 1? This is what escapes the while loop, it adds 1 to i each time it loops through, so when i is > 5 it will stop. Now I challenge you to make a while loop that counts forever. I will show you how to do it in Part 4 if you can't do it. Make sure to comment below with your code for the counter.

That concludes Part 3 of my Python tutorial, I hope you enjoyed yourself, have fun and good coding!

Part 1
Part 2

Profile icon
Profile icon
Profile icon

I am trying to use this multiple input controlled source for POLY model and to get exact dimension. Using is one of the best experience and I think it's a unique service for those students who want to improve their writing skills.

Profile icon

Thank you for the detailed post. Lovely.

Profile icon

Thank you for your post. I have read through several similar topics! However, your article gave me a very special impression, unlike other articles. I hope you continue to have valuable articles like this or more to share with everyone! crossword puzzles

Profile icon

"Thank you so much for sharing all of this fantastic information and how-to's!!!!" Thank you very much! Our expert british essay writer is Here, Kindly share your query and find out the best phyton answers, click the link to know for details and get 20%OFF.

Profile icon

"Thank you so much for sharing all of this fantastic information and how-to's!!!!" Thank you very much! Our expert dissertation help service Here, Kindly share your query and find out the best phyton answers, click the link to know for details and get 20%OFF.

Profile icon

hi am thanks for sharing this code with us I am making now own games like.,

Profile icon

Perfect place to learn python and other programming languages. definitely best writing team and their expertise in their areas of study. Our services are law essay writing services UK, dissertation help, coursework help, assignment help online, etc. If you want to take do my assignment services in UK.

Profile icon
Profile icon

Perfect place to learn about projectors and there information on sports bar

Profile icon

Profile icon
Thanks for sharing this wonderful post. <a href="">google</a>
Profile icon

I want to learn python language because I am very passionate to learn new languages then my dream was to create a website with python that why I am taking help from because they do my coursework for me and they also help me to learn new languages.

Profile icon

I am really impressed with your article!
resize image

Profile icon

When I was building an e-commerce custom site, I had to spend a lot of time on the php and javascrip frameworks, and believe it or not, my first e-commerce project had an incredible custom css design merely because of this flaw of knowledge that website owners post on their blogs. write my assignment for me

Profile icon

Took me time to read all the comments, but I really enjoyed the article. It proved to be Very helpful to me and I am sure to all the commenters here!

Profile icon
alisahwilson offers the best academic services in the UK and all across the world. With our online assignment help, you can easily top your college and university. We have the best writing team and their expertise in their areas of study. Our services are essay writing, case study, dissertation help, coursework help, homework help online, academic study help, etc. If you want to take do my assignment service, hire our assignment writer to help experts today. you can contact us anytime and buy assignment from experts at a very genuine cost.

Profile icon

One of my friends can give this post link and ask me to learn php from that website; I'm a newbie, so if anyone can advise me from A to Z on where I should start, that would be great. I have to handle my site essay help from now on because my friend is on vacation.

Profile icon

A really amazing article. I love it so much!. - . 1v1 lol slope unblocked

Profile icon

With over ten years of experience servicing clients nationally, we feel we are the Top Digital Marketing Company. We use digital platforms to share your story and bind your brand to clients, boosting your company and assisting you in reaching your full online potential.

Profile icon

Hi! People, I’m new to coffee making, so maybe someone more experienced could give me a tip. What are the best beans for cappuccino? It’s my GF’s favorite drink, so I want to learn how to make it perfect.

Profile icon

Add Ivacy google chrome best vpn extension on your google chrome browser and connect to any of their 3200+ servers and protect your online presence.

Profile icon

Want to know what students say about It is a good idea. I like these reviews, they contained fresh info and facts about this service.

Profile icon

Dunno how to jumpstart your essay? Here you’ll get info on how to craft an A-grade assignment with ease! The work will be done in the blink of an eye!

Profile icon

The second time I got help in essay writing, and they met my short deadline again. I'm sure Speedypaper has professional writers, and I will definitely continue to use this site.

Profile icon

Even when clients tell writers online that they are ready to pay to write my assignment, they rarely manage to get the kind of excellence they are looking for. This is where they need to consider contacting a reliable service provider like Crowd Content for expert assistance.

Profile icon

For loops can also be used for a set of other things, not just numbers. Is it true? Source: pay for essay UK of UK Writing Experts.

Profile icon

Recently I have discovered the Python is an easy language to learn and understand the basics of coding, How coding works for and there are different software available to code on. I am taking the python classes from the online source due to the covid. I am it will help me to discover more coding platform.

Profile icon


You should concatenate all your tutorials series into one big tutorial instead of posting several ones! :D