In this exercise, we work with variables, strings, user input and learn a bit about mathematical operators. You should read Dawson's Chapter 2. The source code for the programs he goes through can be found here.
Dawson (p.29) lists several arithmetic operators, but not all. You will have to research further to solve the following exercise.
|Exercise 1.1. Write a program that calculates the following: 5 to the power of 128, 1234 times 678, 1000 divided 15 (true division).|
|Exercise 1.2. Make sure your program prints the results.|
|Exercise 1.3. Write a program that asks the user for two numbers and then calculates: 1) the integer/floor division of those numbers; 2) the remainder of a division (using the modulus operator). Print out the results (and tell the user which result represents what).|
Don't forget to include plenty of comments in your program!
Exercise 2: Write a program that asks the user for his/her birth date and then runs it through the following birthday algorithm. Note that you will need to get the information about the month, the day and the year. You can think about how best to get this from the user (i.e, write your requests for input clearly and get the information in an "easy-to-use" form).
If everything worked correctly, you should get back the original birth date, written in American format (and now you can ask yourself why this worked...).
Exercise 3: This program is taken from Zacharski's book on Python for Linguists (it has been modified a bit). What does it do? NB: TA in English stands for "teaching assistant".
ta = 2 quizzes = 27 to_grade = quizzes // ta remainder = quizzes % ta ta1 = to_grade + remainder ta2 = to_grade print("TA #1 should grade:", ta1, "quizzes.") print("TA #2 should grade:", ta2, "quizzes.")
Exercise 4: Write a program that allows a user to enter two words.
|Exercise 4.1. The program should print out a compounded version. For example, "black" and "board" should result in "blackboard".|
|Exercise 4.2. The program should also ask the user for a number. It should print out the the first word repeated the number of times specified by the user. The second word should be printed out the number that was specified divided by two, but using integer division.|
Please hand in the exercises to aikaterini-lida at uni konstanz by Friday the 7th of November by 11 am.