Author Archives: tywins

Use of loops with “for”

Use of loops with “for”

This program sums a range of numbers given by the user. It’s not inclusive because the range function doesn’t include the last number of said range, as in, for example, if I wanted my range to be from 1 to 10 I would need to write it as range (1, 11), so it would leave out the number 11 and only take those 10 integers i wanted to include in the first place.


*Note: As for the part of the code that says s += i, i learnt it means the same as saying s = s + i so it’s sort of a shortcut for the part of the for statement that does the actual loop.

Use of loops with “for”

Create project with IDE and run inside the IDE

Create project with IDE and run inside the IDE

  1. Open IDLE.
  2. Open a new file.
  3. Type your code as you would type it in any other editor.
  4. Save it (don’t forget to save it as .py)
  5. Then go to the top menu and click on Run > Run Module (F5 for shortcut), and that’s it.

Create project with IDE and run inside the IDE

Use of loops with “while” – Mastery 19

Use of loops with “while” – Mastery 19

This program allows you to sum numbers, until the while statement stops when you enter the number 0.

Use of loops with “while” – Mastery 19

Use of “elif” with a conditional – Mastery 17

Use of “elif” with a conditional – Mastery 17

Use of “elif” with a conditional – Mastery 17

Use of “else” with a conditional – Mastery 16

Use of “else” with a conditional – Mastery 16

The program lacks complexity and verification of the relation username-password but I wanted to make it simple only to show the purpose of the else statement.

Use of “else” with a conditional – Mastery 16

Use of the conditional “if” – Mastery 15

Use of the conditional “if” – Mastery 15

Use of the conditional “if” – Mastery 15

Use of comments in Python – Mastery 07

Use of comments in Python – Mastery 07

The screenshot is very self-explanatory, any line of code that you write in python will be ignored if you add # before said line.

Use of comments in Python – Mastery 07

WSQ07 – Sum of Numbers

WSQ07 – Sum of Numbers

This program allows you to sum the range of numbers between two integers including the last one, I used a counter for the sum and a counter for the digits in between that range of numbers, it equals the counter to the lower bound, when this one’s either lower or equal to the higher bound it stops doing the loop that allows it to sum the numbers in the integer range and prints the total sum of these.

WSQ07 – Sum of Numbers

WSQ06 – Pick a Number

WSQ06 – Pick a Number

This program picks a random number from the range of 1 to 100, so basically it’s a little game where it asks you to enter a number, if the number you entered isn’t the same as the one the program picked, it will inform you if it’s either too high or too low, when the number you entered is the same the program randomly picked it prints “You guessed the number!”

I used while to create a loop where it keeps giving you the option to enter more numbers until you’ve guessed it. And if and else to each case.

WSQ06 – Pick a Number

WSQ05 – Temperature

WSQ05 – Temperature

Sean Paul would love this.

WSQ05 – Temperature