Saturday, August 15, 2015

Intro to Programming with Python - Tutorial 9 - Exercise 2

This is our second exercise for tutorial 9 (https://youtu.be/rW-iqRxP6Cs)

In this exercise we have to redo the exercise from tutorial 8 using a while loop.

So for this exercise:
  • Initialize an empty grades dictionary variable.
  • Prompt the user for the number of students in the class. 
  • Convert the number of students to an integer
  • Use a WHILE loop to allow the user to enter each student name and grade and add them to the grades dictionary.
  • When finished print the grades dictionary back to the user in a friendly manner. You can use the same for loop to pretty print the dictionary as used in tutorial 8
Here is a sample output of running this program:


Here is the code that accomplishes this:

Intro to Programming with Python - Tutorial 9 - Exercise 1

In the 9th tutorial in our introduction to programming using Python series we present the while loops.
The video tutorial can be found here:
https://youtu.be/rW-iqRxP6Cs

Our first exercise for this tutorial is to create a number adder/averager.
When you run your code it should prompt the user to enter numbers until the user says 'Done'
Then it should display the number of numbers the user entered, the total and average for them.

Here is a screen shot of what you should see when you run your program:


The code to accomplish this is as follows:

Sunday, August 2, 2015

Intro to Programming with Python - Tutorial 8 - Exercise

In the 8th tutorial in the introduction to programming with python series we introduced for loops.
The video tutorial can be found here:
https://www.youtube.com/watch?v=b8R9ysVd1sg

The exercise for this tutorial is to make the previous exercise, for tutorial 7, more flexible.
For this exercise:

  • Initialize an empty grades dictionary variable.
  • Prompt the user for the number of students in the class. 
  • Convert the number of students to an integer
  • Use a for loop to allow the user to enter each student name and grade and add them to the grades dictionary.
  • When finished print the grades dictionary back to the user in a more user friendly manner than what we did for the last exercise (See sample program output below)
Here is a sample output of running the program:


Here is the program itself for your reference:


Intro to Programming with Python - Tutorial 7 - Exercise 1

In tutorial 7 in the intro to programming with python series we covered python dictionaries.
The YouTube tutorial can be found here:

The exercise for this tutorial is to build a dictionary for class grades.
Initialize the grades dictionary with five names and marks (You pick names and marks)

Then write a code block that will ask the user to enter a name. 
If name is found in the grades dictionary tell the user what his/her grade is. Then ask if they wish to change the grade. If answer is 'Yes' prompt them to enter a new grade and replace the old one in the dictionary.
If the name is NOT found in the grades dictionary prompt the user to enter a mark and add the name and associated mark to the grades dictionary.

Repeat this FIVE times (Copy and paste this code block)

When done tell the user what the grades dictionary looks like.

Here is a sample output from running the program.


Here is the program: