Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

Fall 2022

BIL 100E - Introduction to Programming Language (Python)

Homework 1

(20p) 1. Write a program that asks the user for a number in the range of 1 through 7. The
program should display the corresponding day of the week, where 1 = Monday, 2 = Tuesday,
3 = Wednesday, 4 = Thursday, 5 = Friday, 6 = Saturday, and 7 = Sunday. The program
should display an error message if the user enters a number that is outside the range of 1
through 7.

(20p) 2. The area of a rectangle is the rectangle’s length times its width. Write a program that
asks for the length and width of two rectangles (hint: 4 inputs). The program should tell the
user which rectangle has the greater area, or if the areas are the same.

(20p) 3. Write a program that asks the user to enter the H+ concentration (mol/L) in their
solution. The program then calculates the pH of the solution and tells the user if the solution
is very acidic (pH < 2), acidic (pH < 7), neutral (pH = 7), basic (pH > 7), or very basic (pH >
12).

(40p) 4. Write the below program in Python:


• The user is first asked if they would like to use HCl, H2SO4, or H3PO4 to prepare an
acid solution.
• If the user enters ‘HCl’ or ‘H2SO4’ or ‘H3PO4’ as input, the program proceeds to the
next step. Otherwise, the program prints an error message.
• The program then asks the user how much acid (in grams) is added to pure water to
make a 1 L solution.
• Depending on which acid has been used to make the solution, the program prints out
the normality (eq/L) of the solution.
Hints: To calculate normality, first molarity (mol/L) is calculated using the acid amount (g) and
the molecular weight of the acid (g/mol), divided by 1 L of solution. Then molarity (mol/L) is
converted to normality (eq/L) using the equivalents (eq/mol) for the type of acid that is being
used. Molecular Weights - HCl: 36.5 g/mol, H2SO4: 98.1 g/mol, H3PO4: 98.0 g/mol
Equivalents - HCl: 1 eq/mol, H2SO4: 2 eq/mol, H3PO4: 3 eq/mol

Example: User enters “H2SO4” for the acid, and 10 grams as the amount of acid added.

Moles of acid added = 10 g / 98.1 g/mol = 0.102 mol


Molarity of solution = 0.102 mol / 1 L = 0.102 mol/L
Normality of solution = 0.102 mol/L * 2 eq/mol = 0.204 eq/L

You might also like