Think Twice
Code Once
The Islamic University of Gaza
Engineering Faculty
Department of Computer Engineering
Fall 2017
LNGG 1003
Khaleel I. Shaheen
Introduction to Computers
Laboratory Manual
Experiment #2 Solution
Elementary Programming, I
Experiment #2: Elementary Programming, I
Homework
1. Write a program that converts miles into kilometers. Use the following algorithm:
a. Use a variable named miles that read value from keyboard.
b. Multiply miles by 1.609 and assign it to a variable named kilometers.
c. Print the value of kilometers.
miles = input("Enter miles: ")
kilometers = miles * 1.609
print(str(miles) + " miles equals " + str(kilometers)
+ " kilometers")
2. Classify the following identifiers as either valid or invalid Python identifier:
Valid is blue. Invalid is red.
basem $a if 2k my app
Test $5 x +9 _a
x+y #44 width my_app _
A# myApp If my-app _5
3. Write a program that reads in the radius and length of a cylinder and computes the
area and volume. Here is a sample output:
Enter the radius and length of a cylinder: 7.5, 15
Area is 176.7144
Volume is 2650.7166
radius, length = input("Enter the radius and length of a
cylinder: ")
area = 2 * radius * radius * 3.14159 + 2 * 3.14159 * radius * length
volume = radius * radius * 3.14159 * length
print("The area is " + str(area))
print("The volume of the cylinder is " + str(volume))