# Python exercises

Institute for Environmental and Spatial Analysis...University of North Georgia

## 1 Arithmetic calculator

**Keywords:**keyboard input, looping, slicing, branching

Write a simple calculator that supports four basic arithmetic operations (`+`

, `-`

, `*`

, and `/`

) for two floating-point numbers.

- Print “
`?`

” and read an expression - If the expression is
`quit`

, stop - Split the expression into three parts: left operand, operator, and right operand
- Branch based on the operator
- Calculate the expression and print its result
- Go to step 1

## 2 Dice rolling

**Keywords:**keyboard input, probability,

`random()`

Python provides a pseudo-random number generator in the `random`

module. We’ll use the `random()`

function from this module to write a dice rolling simulator. This function takes no arguments and returns a pseudo-random `float`

between $[0,1)$. That is, $0\le\text{random()}<1$. The workflow of this program should be as follows:

- Print “
`Roll?`

” and read a string input - If the input is
`quit`

, stop - Take a random number from
`random()`

- Print one of 1–6 based on the random number from step 3
- Go to step 1

Do NOT use `randint()`

. Only use these three functions: `random()`

, `print()`

, and `input()`

.

## 3 HTTP client

**Keywords:**http, http.client, open

Write a simple HTTP client that downloads https://hcho.isnew.info/gisc-3200k.html and saves it as test.html.