# Recitation Week 4 – String Formatting solution

\$9.99

Original Work ?

## Description

5/5 - (1 vote)

Problem 1. Ask the user to enter an ASCII value. Print the character associated with the ASCII
value. [10 pts]
Sample run:
Enter an ASCII value: 66
The character for ASCII code 66 is B
Problem 2. Ask the user to enter a string and an integer (let’s say n). Print the string n times, once
per line. You should use the print() statement only once in your program. [15 pts]
Sample run:
Please enter a string: Hello python!
Hello python!
Hello python!
Hello python!
Hello python!
Hint: Use newlines and string arithmetic to achieve this.
Problem 3. Given a floating point number 0.457467657, print the same number with a precision
of 3 decimal places and right justified to a column of 10 characters. [10 pts]
Sample run:
0.457
Note: Whitespace (blank spaces / blank lines) matters; make sure your whitespace exactly
matches the expected output.
Problem 4. Ask the user to enter the number of males and number of females registered in a
class. Display the percentage of males and females in the class. You should use string formatting
operators to get the percentage value (e.g. 60.00%) from the fraction value (e.g. 0.6). For
example, if there are 8 males and 12 females, percentage of males in the class is 8 ÷ (8 + 12) = 0.4
(display this value as 40.00%). Your percentage value should have a precision of maximum 2
decimal places. [15 pts]
Sample run:
Enter the number of males: 8
Enter the number of females: 12
Percentage of males = 40.00%
Percentage of females = 60.00%