Monday, January 6, 2014

Dice! Dice! READ All About It!

Summary:
This program was designed to analyze the data from the Dice Saving program earlier. What the program does is it opens the text file read mode, Takes the amount of lines in the program and divides that by four. It does that because there are four lines for each roll. It then prints the amount of rolls that it just determined, and closes the file. Then it sets the amounts of sevens and double sixes in the document to 0 so it is ready to search for how many there are. Then while the amount of Lines discovered earlier is greater than the amount of lines scanned it searches for totals of 7 and roll1's and roll2's of 6. Finally it prints out the information it searched for and found.
Issues:
The main issue in this program was getting it to search for the correct thing. The tricky part is that when we wrote to text file, we put a new line after every number entered. So when reading the file we had to search for the number with the new line (\n) included. This confused a lot of people. 
Profit:
Just like in the writing program this reading program is useful for learning how to save games. Also it gave us a nice little reminder that we have to be very careful because computers search for exactly what they are told to do and wont assume anything for you. 

Put that Roll in a To-Go Box, We Want to Save it for Later!

Summary:
The point of this program was to use the dice rolling program to write to a text file in order to be analyzed later. I did this by opening the file, setting 3 variables to the variables from the Dice Roll program to save some time later on, and asking how many times the player wants to roll. Then, while the amount of rolls done, is less than the amount of rolls wanted it rolls the dice, then it writes that to a file with f.write command and then a blank line after. All this is repeated again until the amount of requested rolls has been achieved. 
Issues:
It was difficult to find the command to write information to a file as it had not been covered in our codeacademy lessons. Also figuring out how to make the printed information go into another line was difficult, but we figured out that it was \n.
Profit:
This is important so that we can learn how to save games in the future. But also to get a more complete knowledge of python.

Aww Craps!

Summary:
This assignment was to make a program that simulates the game craps. First of all, it imports the Dice rolling program from earlier, and takes the various Dice rolls from that. Then based on the sum of those rolls it determines the result of what would happen in a game of craps. If the roll is not one that would initiate point mode, then the player instantly wins. But if it is not an instant win roll, point mode is activated. When point mode is activated the player tries to roll the number that initiated point mode, before rolling an 7 or 11. Then the player is asked if they want to roll again, and if they do the program restarts.
Issues:
Originally I went for the brute force method, with the intent of saving mental effort at the exchange of a bit of time. All that time amounted to nothing, and I wound up restarting and going with the point mode method that I have now. Another issue was getting the program to roll more than once, but I managed to get it working by reloading the dice program after any roll was completed.
Profit:
This project was great for putting all of our skills together, as well as learning how to import our own previous programs as modules. Importing our own programs as modules comes back often in future programs.

Dice, Dice, Baby!

Summary:
This program is extremely simple, and it basically is just reusing past knowledge. It imports a random module, sets the first dice to random numbers one through 6, then adds them together for the Dicesum variable. Finally it sets the Diceprint variable to a string combining the first number, then a space, the second number, then a space, and then "Total of", then another space, and then the total of the two dice. The purpose of the Diceprint variable is so that all of the data can be easily printed in future programs. Also, this is my first program that I used a comment in, the comment is completely irrelevant because it was mainly just a test. 
Issues:
There were no issues in this program worth noting. 
Profit:
I learned how to use comments from this program, also the program reenforced past knowledge so it was not forgotten.

Conversion Machine!

Summary:
Our second assignment was to make a "Conversion Machine!" This program first asks which general type of conversion should be run. 1 = Distance, 2 = Temperature, 3 = Binary. Then once in the desired option for which type of general conversion is selected, the program asks for which specific conversion type should be used ("A --> B or B ---> A?"). Then the appropriate conversion factors are applied and the converted result is printed. 
Issues:
The main issue, which wound up not even being included was binary. Binary is fairly confusing in the first place, so bringing it into a python program was out of my league at the time. Also this program does not repeat or defend against the "Bleen Test"*
Profit:
This program's main purpose was to make sure everybody knew how to use operators in python, and it achieved its task. I quickly got the hang of using operators, which are used in almost every future program we did. 
*Side Note:
The "Bleen Test" is a test created by Mr. Medvitz which is essentially intended to see if the program is idiot proof. For example, if the program needs an input of 1, 2, or 3, and someone inputs "Bleen" or "7" that will break the program unless there are measures taken against that. 

Back in Business with Python!

Summary:
We spent the first week or so in the new unit learning simple python knowledge with codeacademy, after that week we transitioned into making our own projects. The first project we were assigned, was to make our own "Rock Papper Scizzors" game. This was my first experience with while loops, and importing modules, so that was difficult to get the hang of at first. The way the program works is while play is 1, the program asks the player to input a number depending on whether they want Rock, Paper, or Scissors. Then the computer randomly selects a number for Rock, Paper, or Scissors and those numbers are compared by saying if the players number is equal to one thing, and the computers is equal to another, depending on how the game would be played in real life a winner is chosen. If the player's input is not equal to 1, 2, or 3, the program requests that the player inputs an allowed number so that the calculations actually work. Finally, the program asks if the user would like to play again, if so since play will still equal 1, the program will restart, but if anything else is entered, the program will stop.
Issues:
The main issues revolved around having some variables set as strings in some areas, and integers at others. This was fixed by making the random compy variable a string using the "str()" command. 
Profit:
With this program I learned how to appropriately use while loops, import modules, and keep my strings and integers in order. Mastering the art of the while loop is very important, as it is needed for programs that need to be repeated many times. Modules are very important, as they are used often in most programs. One form of importing a module is very useful and we will visit it later.