0% found this document useful (0 votes)
17 views2 pages

Ex 04

Uploaded by

augchen08
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views2 pages

Ex 04

Uploaded by

augchen08
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Exercises 4 – Variables

Each of the following programs should begin with a program header block
comment. Ensure that each program is using good output style.

1. Prompt the user for the radius of a circle and output the area of the circle.
Round your answer to one decimal place.
Be sure that your program has good output style. It should prompt the user
for their number, and then it should explain what the answer represents.

For example, your program should look something like this when it runs:
(In this example, underlined text represents information the user typed in.)

Enter the radius of a circle: 5


The area of your circle is 78.5 square units.

Save your completed program under the file name: 4_1.py

2. Prompt the user for the length and width of a rectangle and output the area.
Just as with exercise 1, ensure your program is using good output style.
Save your completed program under the file name: 4_2.py

3. Prompt the user their full name and then print three lines.
On the first line of your program, it should print the user’s name once.
On the second line, your program will print the user’s name twice.
On the third line, your program will print the user’s name three times.
You may use the default separator behavior when printing the names.

Save your completed program under the file name: 4_3.py

4. Write a program that will prompt the user for a number of dollars (as a whole
number) and then prints the number of quarters with an equivalent value.

Save your completed program under the file name: 4_4.py

PROGRAM 4_5.py ON THE NEXT PAGE


5. Write a program that does the reverse of 4_4.py:
It will prompt the user for a number of quarters and then prints how many
dollars would have an equivalent value to those quarters, and how many
quarters are left over.

For example, your program should look something like this when it runs:
(In this example, underlined text represents information the user typed in.)

How many quarters do you have? 19


You can get 4 dollars.
There will be 3 quarters left over.
HINT: You will have to use integer division (//) and the modulo operator (%)

Save your completed program under the file name: 4_5.py

6. What data types are the following values?

Value Type Value Type

"Hello!" string 12 integer

2.5 float 12.0 float

"Seven" string "7" string

2 + 3.5 float "7.0" string

7. For each of the following variable names, state whether it is a good name, a
bad name (but still works), or if it will cause a syntax error.

Variable name Good/Bad/Error Variable name Good/Bad/Error

userName good 1stVar eroor

acvnwenw bad fav colour error

choice2 good MyNum bad

x32 bad can$ bad

height_cm good answer# good

You might also like