You are on page 1of 1

Technische Universit at M unchen Institut f ur Informatik Tobias Neckel

GRS, June 2013

Python course - Tutorial 1


Mastering Python syntax and control structures
First of all, make sure that you understand the basic functionality of Python, i.e., variables, control structures and functions. Write a simple Python script, which reads in a string from the terminal; you can use the Python function raw input(). Access the python online documentation for details on this method. The script should store the read-in string in a variable and print it to the terminal Improve the previous script. Assume that the user-provided string represents an Integer (e.g. the string 13). Calculate the sum of all values from 1 to the given value. To achieve that, you have to convert the string to an integer. Use a loop to do the summation. Further improve the script by putting the summation into a funtion which gets the user-string as a parameter and returns the sum.

TicTacToe

For this task, most of the description is in a le you have to download from the course website (http://www5.in.tum.de/ -> Teaching -> GRS Compact Course... -> Other Files -> tictactoe.py). The goal is to implement part of a TicTacToe game. The le provides the structure and some functionality. All parts which have to be implemented by you are marked by the text TODO. Try to implement all missing functionality. (Hint: test each function that you implemented independent of the whole program.) Advanced challenge: If you implemented the function computerStep as described in the function comment, the computer player is very dumb, as it picks elds randomly. Try to implement an intelligent computer player which cant be defeated.

You might also like