class logo

CS 122 - Day 6 Exercises

This page lists some problems for today's class. After today, you should be able to solve these problems on your own. Problems with this color are more challenging.

Scratch vs Python

Some commands are very similar between scratch and python. Here are some mappings

Scratch Python
say print
change x by 1 x = x + 1
if <condition> if <condition>:
forever while True:
ask "" and wait answer = raw_input("")
stop all import sys
sys.exit()
wait 1 secs import time
time.sleep(1)
1) A simple program

Write a program to print out some simple information about yourself. It doesn't need to ask for any input, just print things

2) Tip calculator

Write a program that asks the user for an amount, calculates what 15% of that is, and prints it out.

3) Area

Write a program that asks the user to enter the width and height of a wall. It should calculate the area of the wall and print out the value.

4) Madlibs

Ask the user to enter a verb, a noun, and an adjective and then print out a sentence using those words as fill in the blank values to a preprogrammed sentence.

5) BMI Calculator

The Body Mass Index (BMI) value is a simple way of evaluating a person's height to weight ratio. Implement a BMI calculator, asking the user for their weight in pounds and their height in inches. The formula is:

BMI = (weightInPounds * 703) / (heightInInches * heightInInches)

6) Length conversion

Write a program that converts between a decimal value of feet into feet and inches. For example, 5.5 feet should be converted to 5 feet, 6 inches. Write another program that converts feet and inches to a decimal value for feet.