Assignment 1

Due Mon, July 15

Please create a single zip file named <userid>-hw1.zip (i.e. paul-hw1.zip) that contains four files:
hw1-1.py (the solution of question 1)
hw1-2.py (the solution of question 2)
hw1-3.py (the solution of question 3)
hw1-4.py (the solution of question 4)

Email your solutions to zschneider <at> berkeley.edu. Include comments in each script stating your name, the name of any collaborators, and approximate time it took you to complete the exercise.


1. Write a script that prompts the user for a number of gallons of gasoline. Reprint that value, along with its conversion to other measurements:

Figures to use:

2. Write a script that prompts the user for their name. Print the name with the letters reversed. You may use s.lower() and s.upper() to change a string s to lowercase and uppercase letters.

Enter your name: Paul
Luap

If the name is the same forward and backwards, print "Palindrome!" on the next line.

Enter your name: Ana
Ana
Palindrome!

Hint: use a loop that counts downward.

3. Write a script that prompts the user for an integer tree size, then displays a number tree as shown below:

Enter a size: 5
    1
   121
  12321
 1234321
123454321

If you are having trouble, see the hint here.

4. Write a script that prompts the user for an integer, N. Display an NxN checkerboard as shown:

Enter a size: 4
X X
 X X
X X
 X X

Enter a size: 5
X X X
 X X
X X X
 X X
X X X