Back to Basics

Introduction

My absence today gives us an opportunity to practice several fundamental concepts from earlier in the course, while still honing our GUI programming skills.  Below is a series of exercises that will allow you to show off your newly acquired skills

The major concepts used in each of these programs are:

  • Arithmetic
  • Importing modules from PyQT4
  • Box Layouts
  • GUI Entry
  • GUI Buttons
  • GUI Output

Complete each exercise with the appropriate file name and then submit all files using this submission link.

If you have questions during the hour, please email me.  I may be able to respond this morning. And, if you are having trouble remembering how to use complete the exercises, recall that we already wrote similar programs,  including one to add two numbers.

Exercise 1: lastnamefirstname-circlearea.py

Write a GUI program that that computes the area of a circle. The program should present a graphics window, a line edit for the radius, a button to execute the area calculation, a label object for the output, and a quit button.

circlearea

Exercise 2: lastnamefirstname-exchange.py

Please go to xe.com and find out the current exchange rate from dollars to euros (the European currency).  Then create a program that converts dollars to euros. The program should present the user with a  window, a line edit for the number of dollars, a button to convert that amount to euros, a label object to display the result, and a quit button to end the program. I’ve drawn a mock-up of the GUI below.

dollarstoeruos

Exercise 3:  lastnamefirstname-jennyspizza.py

At Jenny’s birthday party she orders a 32 piece pizza. Have the user (probably Jenny) enter the number of people at the party that will be eating pizza and output the number of slices each one gets. As you know the pizza might not divide evenly. There are two ways to handle this. The first is to ignore the extra pieces and give everyone the same amount. The second way is to cut up the extra pieces so that everyone gets the same amount. Your program must output both options.

So, the requirements of the program are that it should present a window, an line edit for the number of people attending, a button to compute the solutions, a label object for the integer answer, a label object for the decimal answer, and a quit button. Again, I’ve drawn a mock-up below.

jennyspizza

 

When You’re Finished

Now that you have completed the three exercises, it’s time to relax a little (assuming you have submitted your other outstanding programs such as Memory and the Dragon Web Browser). Instead of getting online and playing some game you didn’t write, let’s take a look at how a real game is made. Please read the tutorial found here.  It describes the creation of a game called Snake. In the reading,  you’ll see a link to a file called snake8.py.  Save this file to your H: drive and then open it with IDLE.  You should be able to run the program and play the game.

Once you are familiar with the game, find the line of code that determines the size of the game board and change it to a 16×16 or even 25×25 board.  Then play some more. See below:

snake