Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
8 views

Lecture 3 Python Self notes

The document outlines several programming problems related to Python, including classifying triangles, earthquake magnitudes, letter grades, visible light wavelengths, and electromagnetic radiation. Each problem requires the user to input specific data and display corresponding results or messages. Additionally, it includes examples of loops and calculations, such as conversion tables and averages.

Uploaded by

amedalsaby
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)
8 views

Lecture 3 Python Self notes

The document outlines several programming problems related to Python, including classifying triangles, earthquake magnitudes, letter grades, visible light wavelengths, and electromagnetic radiation. Each problem requires the user to input specific data and display corresponding results or messages. Additionally, it includes examples of loops and calculations, such as conversion tables and averages.

Uploaded by

amedalsaby
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/ 25

HCI- Python Programming

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.

Write a program that reads the lengths of 3 sides of a triangles from


the user.
Display a message indicating the type of the triangle.
Problem 1 Sol.
Problem 2
• The following table contains earthquake magnitude ranges on the
Richter scale and their descriptors: Magnitude Descriptor
Less than 2.0 Micro
Write a program that reads a magnitude from 2.0 less than 3.0 Very minor
the user and displays the appropriate 3.0 less than 4.0 Minor
descriptor as part of meaningful message. 4.0 less than 5.0 Light
5.0 less than 6.0 Moderate
6.0 less than 7.0 Strong
7.0 less than 8.0 Major
8.0 less than 10.0 Great
10.0 or more Meteoric
Problem 2 Sol.
Problem 3
Letter Grade points
• At a particular university, letter grades are mapped A+ 4.0
to grade points in the following manner: A 4.0
A- 3.7
Write a program that begins by reading a letter B+ 3.3
grade from the user. Then your program should B 3.0
compute and display the equivalent number B- 2.7
of grade points. C+ 2.3
Ensure that your program generates an C 2.0
appropriate error if the user enters an invalid letter C- 1.7
grade. D+ 1.3
D 1.0
F 0
Problem 3
Sol.
Problem 4
• The wavelength of visible light ranges from 380 to 750
nanometers(nm). While the spectrum is continuous, it is often
divided into 6 colors as shown below: Color Wavelength(nm)
Violet 380 to less than 450
Write a program that reads a wavelength
from the user and reports its color. Blue 450 to less than 495

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

Orange 590 to less than 620

Red 620 to 750


Problem 4 Sol.
Problem 5
• Electromagnetic radiation can be classified into one of 7 categories
according to its frequency, as show in the table below:
Name Frequency range(Hz)
Write a program that reads
the frequency of the radiation Radio waves 𝐿𝑒𝑠𝑠 𝑡ℎ𝑎𝑛 3 ∗ 109
from the user and display the Microwaves 3 ∗ 109 𝑡𝑜 𝑙𝑒𝑠𝑠 𝑡ℎ𝑎𝑛 3 ∗ 1012
appropriate name. Infrared light 3 ∗ 1012 𝑡𝑜 𝑙𝑒𝑠𝑠 𝑡ℎ𝑎𝑛 4.3 ∗ 1014
Visible light 4.3 ∗ 1014 𝑡𝑜 𝑙𝑒𝑠𝑠 𝑡ℎ𝑎𝑛 7.5 ∗ 1014
Ultraviolet light 7.5 ∗ 1014 𝑡𝑜 𝑙𝑒𝑠𝑠 𝑡ℎ𝑎𝑛 3 ∗ 1017
X-rays 3 ∗ 1017 𝑡𝑜 𝑙𝑒𝑠𝑠 𝑡ℎ𝑎𝑛 3 ∗ 1019
Gamma rays 3 ∗ 109 𝑜𝑟 𝑚𝑜𝑟𝑒
Problem 5 Sol.
Python loops (While loop)
Python loops (While--else loop)
Python loops (For loop)
Example 1
Write a program that displays conversion table for degrees Celsius and degrees
Fahrenheit. The table should include rows for all temperatures between 0 and
100 degrees Celsius that are multiple of 10 degrees Celsius. Include appropriate
headings on your column.
Example 1 solution
Example 2
Print number of asterisks.
Example 3
Print multiplication table –
row 9
Example 4
Calculate the geometric average of a list of numbers, using the
formula

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.

Hint: Because the 0 marks the end of the input


it should not be included in the average.
Thanks

You might also like