Linguistic Gaming with Python

Python Practice 3

In this exercise we work mainly with if-elif-else statements and while loops, but also learn a little bit about some functions which can operate on strings. You should read Dawson's Chapter 3. The source code for the programs he goes through can be found here.

Exercise 1: Write a program that asks for the first and last names of a person. Something like this.

Please enter your first name:

Please enter your second name:

  1. Figure out (look this up in books or on the web) what the functions len(), min() and max() do.
  2. Using these functions, figure out:
    1. how long the first and last names that were input are and print out the result (e.g., your last name consists of 4 letters).
    2. what the "smallest" letter in the first name is
    3. what the "largest" letter in the last name is
  3. Note that people might input their names in various ways, e.g. "Miriam", "MIRIAM", "MIriam", "miriam". Fix your program so that the exact nature of the user input doesn't matter. You could use the string operation X.capitalize(), for example.
  4. Your final output should look something like this:
    You are called Miriam Butt. 
    Your first name consists of 6 letters. 
    Your last name consists of 4 letters. 
    Taken togehter, your name consits of 10 letters.
    The "smallest" letter in your first name is 'a'. 
    The "largest" letter in your last name is 'u'. 

Exercise 2: Write a program which simulates the throwing of two dice. Inform the user which dice won, i.e., had the higher number.

Exercise 3: Write a program that asks the user for a number and then produces exactly as many random numbers as specified by the user. You should use a while loop to do this.

Exercise 4: Go through Dawson's Losing Battle program. Modify the final version (the one without the infinite loop) so that it includes several different possible scenarios. I.e., the scenario does not always involve a troll thumping our hero. Ogres could come out in addition, as could good witches with healing potions to restore our hero's health. Bring your program (or your ideas) to class, where we will discuss them.

Please hand in the programs for the exercises to aikaterini-lida at uni konstanz by Friday the 14th of November by 11 am.