Sitemap
Varich Boonsanong

Varich Boonsanong

[python series ] List and For — loop

Some problems about normal variable

Prob: make me 100 variables.

you : um…. let me think.

you: Okay from my knowledge. I would go like.

(while you are writing this program [the full one] ) :“Why would I do this , it’s such a painful and a waste of time.”

P: “Many of my friends have the same birthday (it’s tdy) . Can u help me to told them HBD all. (There are only 100 people)”

For old style:

List :

list is just an “list” (collections) of var

Instead of old one we use.

Done.

We declared a set of list which contains 12 variables

Get Varich Boonsanong’s stories in your inbox

Join Medium for free to get updates from this writer.

Q: How can i access each element(variable)?

Method

Method is a kind of function that manipulate on the list. Let’s see example!

For-loop:

In programming , Most of the time we need to do the same thing over and over again So to be robust and lazy. There are a thing call loop i.e. it loop the instruction for you.

Q: how can I print all of the number in list ?

Q: how can i print number from 1 to 100 ?

While-loop:

It’s can be best describe as a follow code.

Problems

  1. Print 1 to 1000 in the same line. (if u use the code above it’s line make a new line for every number) [hint][u need list + loop]
  2. Get 10 numbers and print the summation.
  3. Collect 10 numbers and find mean and median.

Special

  1. Ask for 10 number collect them all and print each one of them in increasing order.