Lecture 3 Python Self notes
Lecture 3 Python Self notes
Problem 1
• A triangle can be classified based on the lengths of its sides as
equilateral, isosceles or scalene. All 3 sides of an equilateral triangle
have the same length, An isosceles triangles has two sides that are
the same length, and a third side that is a different length.
If all of the sides have different length, then the triangle is scalene.
Display an appropriate error message if the Green 495 to less than 570
wavelength entered by the user is outside
of the visible spectrum. Yellow 570 to less than 590
Test your program with the following six data items 6.2, 12.3, 5.0,
18.8, 7.1, 12.8. compare the results obtained with the arithmetic
average of the same data, which average is larger.
Example 4 solution
Example 5
Write program that reads a positive integer from the user and then
displays the sum of all the integers from 1 to n. the sum of the first n
positive integers can be computed using formula: Sum=n(n+1)/2
Example 7
• Write a program that displays conversion table for degree Celsius
and degrees Fahrenheit. The table should include rows for all
temperatures between 0 and 100 degrees Celsius that are steps of
10 degrees Celsius. Include appropriate headings on your column.
F = 𝐶 ∗ + 32
5
F = 𝐶 ∗9/5 + 32
Example 7 sol.
• In this exercise you will create a program that
computes the average of collection of values
entered by the user. The user enter 0 as a sentinel
value to indicate that no further values will be
provided. Your program should display an appropriate
Assignment error message if the first value entered by the user is
0.