CS270 Blog


This is the brief PowerPoint presentation I gave during my Python Language Presentation.



High Level Project: Mastermind Game

For my high-level Python program, I chose creating a text-based version of the popular board game Mastermind.

HOW TO PLAY

The player has 10 chances to guess the secret number code.

Specifications:

1.    Set difficulty by inputting number.

a.    Determines length

2.    You can have code length of 10 ints.

3.    10 Chances to guess the secret number.

4.    Program keeps track of

a.    Numbers placed in the correct place

b.    Numbers correctly guessed

c.    Number of guesses left.

Set the difficulty
Begin Entering Combinations

You’ve won!!!


Beginning this project, I was nervous as to whether I would be able to code such a game as Mastermind. Fortunately, Python’s simple syntax was pretty easy to understand. I was able to adjust to Python’s syntax and begin coding.

My impression of Python is that its so much easier to code in than Java. Of course I made rookie mistakes along the way, importing libraries that weren’t necessary, etc.

My biggest challenge was somewhat self-inflicted: I tried converting my Python 2.73 code to 3.22 (the most current version). When I ran the program, I was able to set the difficulty. However, when I entered a combination, I got the error illustrated below:

The above error message pointed to the line of code below circled:

Unfortunately after hours of research, I couldn’t find a solution. Welp…at least I was able to get my Python 2.73 code working.

Here’s a link to higher-quality screenshots from above

Here’s a link to the code.

***View the latest post for the PowerPoint presentation I gave during class.***


High-Level Python Program Idea

For my High-level Python program, I will build a text-based version of Mastermind. 


Mid-Sized Python Program: “I’m thinking of a number…”

After studying up on the Python Programming language, I was able to implement random int generators, raw input from the user, loops, and printing.

Again, here’s how the program works:

This Python program will ask the user for his/her name. After taking raw input from the user, it will randomly generate a number between 1-20. The program will print “I’m thinking of a number between 1-20.”

While the number of guesses made are less than 6, the program will print “Take a guess: ”. Each time the users inputs the incorrect number the number of guesses made thus far are stored and incremented. If the user’s guess is less than the actual number, the program prints “Your guess is too low.” If the user’s guess is more than the actual number, the program prints “Your guess is too high”.

If the user guesses the correct number, the program prints “Good job (whatever the user’s name is)! You guessed my number in (however many) guesses!” If the user guesses the wrong number 6 times, the program prints “”Nope. The number I was thinking of was {whatever the randomly-generated number is)”. The program terminates.

Running the program:

Here are some screen shots of how the program works:

This is a link to higher quality screen shots.


Proposal For Medium Level Python Project

For my mid-sized Python Program, I propose that I work with random int generators, raw input from the user, loops, and printingAll of these are heavily used in just about every programming language. Why not learn how to program them in Python?

Here’s a plan:

This Python program will ask the user for his/her name. After taking raw input from the user, it will randomly generate a number between 1-20. The program will print “I’m thinking of a number between 1-20.”

While the number of guesses made are less than 6, the program will print “Take a guess: ”. Each time the users inputs the incorrect number the number of guesses made thus far are stored and incremented. If the user’s guess is less than the actual number, the program prints “Your guess is too low.” If the user’s guess is more than the actual number, the program prints “Your guess is too high”.

If the user guesses the correct number, the program prints “Good job (whatever the user’s name is)! You guessed my number in (however many) guesses!” If the user guesses the wrong number 6 times, the program prints “”Nope. The number I was thinking of was {whatever the randomly-generated number is)”. The program terminates.



Cedric’s new programming language: PYTHON!

Python Logo

Hello folks! So as a part of my CS270 course, each student is to learn a new programming language during the semester. I chose the Python programming language. Python is a dynamic language that is being used for a wide variety of programming purposes.

Below are some features of the language provided by the official Python website:

  • very clear, readable syntax
  • strong introspection capabilities
  • intuitive object orientation
  • natural expression of procedural code
  • full modularity, supporting hierarchical packages
  • exception-based error handling
  • very high level dynamic data types
  • extensive standard libraries and third party modules for virtually every task
  • extensions and modules easily written in C, C++ (or Java for Jython, or .NET languages for IronPython)
  • embeddable within applications as a scripting interface

For our first assignment with our new language, we were told to print “hello world!” In order to complete this assignment, I first had to install Python. Then, I had to find a good compiler. After conducting some research, I stumbled upon a premium compiler called Wing IDE 4.1.

Because of Python’s very clear and simple syntax, this assignment was extremely simple. 

All I had to type was print (“Hello world!”). 

Higher Resolution Image Here

I love Python!!!


Program Bug

As a Computer Information Systems student, I have encountered some problems with my programs. For one particular program, I had to write computer code that would create six faces, using a combination of circles and rectangles (circles for the head, eyes, and mouth/rectangles for the hair). Instead of writing the code for each individual face six times, I had to use an array. An array stores numbers, or variables. Arrays make it so you only have to write the code that creates a face once.

One bug that came up in my program was a result of not creating space in between each face. So when I ran the program, it compiled but created 6 faces in one location, on top of each other. I fixed this problem by applying the following calculation: “GAP” amount + the index amount*2. I was able to fix this problem because from the very beginning, I wrote comments in my code describing what each section of code did.


11
To Tumblr, Love PixelUnion