Problem_set_python(1)
Problem_set_python(1)
Aerospatial engineering
2024-2025
Part I
Python programming
1
Chapter 1
2
CHAPTER 1. BASIC INPUT/OUTPUT AND MATH 3
i. In octal;
ii. In hexadecimal.
(c) Create a Python program to count the number of 1s in a binary
number of 4 digits. [HARD]
3. Floating point
(a) Write a Python program that takes two floating-point numbers as
input and calculates their average (mean). Print the average.
(b) Build a Python program that reads a decimal number (floating-point)
from the user and rounds it to a specified number of decimal places.
The number of decimal places should also be entered by the user.
Print the rounded value.
(c) Build a Python program that reads a decimal number (floating-point)
from the user and calculates its square root.
(d) Build a Python program that reads four numbers, where the first
two define the point (x1 , y1 ) and the second ones the point (x2 , y2 ).
Calculate and show the distance between them.
(e) Design a program that converts currency amounts between two dif-
ferent currencies. Ask the user for the exchange rate and the amount
in one currency, then calculate and display the equivalent amount in
the other currency.
4. Physics
(a) Calculate a program to convert Celsius degrees into Farhenheit. The
formula is as follows:
9
F = C + 32
5
where C and F are given by the user.
1.3 Aerospace
Some problems in aerospace that only require basic mathematics
• Read the distance traveled and the amount of fuel consumed from the
user.
CHAPTER 1. BASIC INPUT/OUTPUT AND MATH 4
• Calculate the fuel efficiency (in liters per kilometer) by dividing the amount
of fuel consumed by the distance traveled.
• Calculate the fuel efficiency in miles per gallon (1 liter = 0.264172 gallons,
1 kilometer = 0.621371 miles).
• Display the fuel efficiency in liters per kilometer and miles per gallon to
the user.
You can assume standard values for T0 and the temperature lapse rate. After
calculating TAS, display it to the user.
all given in years. Given the velocity of a spaceship and a number of years,
calculate the number of years experienced by the astronaut.
Input velocity(m/s): 10
Input number of years: 7
The number of years experienced by the astronaut is: 6.999999999999996
7. Calculate the area between two given points of the cos function. Remem-
d
ber that dx sin(x) = cos(x).
7
CHAPTER 2. THE NUMPY, RANDOM 8
2.1.4 Rounding
Using the numpy package, write programs to:
2.3 All
1. Consider that the launch of space ship is conditioned by the weather
conditions and the mechanical conditions, both subject to random
oscillations. Implement a program that:
• Reads an interval of two integers from the user, regarding the me-
chanical conditions;
CHAPTER 2. THE NUMPY, RANDOM 9
30 t = r e s o l v e _ t _ p a r a _ y _ i g u a l _ a _ z e r o (v , g , angulo )
31 x_queda = calcula_x_dado_t (v , t , angulo )
32 dist = distancia ( x_queda , 0 , x_do_alvo , 0)
33
1
xt = v.cos(θ).t; yt = v.sin(θ).t − .g.t2
2
Implemente:
If statements
3. Implement a ’Rock’, ’Paper’, ’Scissors’ game: ask the user for his play,
generate a random item from the collection, see who wins!
4. Implement a program to calculate the body-mass index, given user’s height
and weight in meters and kilograms respectively. Index is calculated as
weight/(height2 ). The conclusions shall be as follows:
• 18.5 to 24.9 - Healthy;
• 25 to 29.9 - Overweight;
• Over 30 - Obese.
11
Chapter 4
Recursivity
12
Chapter 5
3. generate and show a multiplication table asked by the user, or all of them.
4. implement a count down number;
5. play a guessing number game: generate a random number and give feed-
back to the user until it is guessed right. Give him the option to continue
or quit and count the number of attempts it took to guess the right num-
ber.
6. Reverse the digits of a number.
7. Collatz Sequence Length: Given a number, apply the following rules
until the number becomes 1:
10. Make a program to calculate the function arctan, given by the following
formula:
∞ n
x XY 2kx2
arctan(x) =
1 + x2 n=0 (2k + 1)(1 + x2 )
k=1
13
CHAPTER 5. WHILE AND FOR INSTRUCTIONS 14
Tuples, Lists
6.1 Tuples
Write programs to:
1. Tuple creation: Create a tuple with elements of different data types and
print the type of each element.
2. Tuple Indexing: Given a tuple, print its first and last element;
3. Check if an element exists in a tuple;
4. Count the existence of an element in a tuple;
5. Find the Outlier: In a tuple of numbers, there’s one strange number (or
vice versa). Find it and returns this number.
6.2 Lists
1. (Basic lists)
(a) The len (list) fuction, that counts the number of elements on a list;
15
CHAPTER 6. TUPLES, LISTS 16
6.3 Strings
Make programs to:
7.1 Dictionaries
Implement programs to
1. Create a dictionary. Add, change and remove values for a given key.
2. Eliminate repeated elements from a list;
18
CHAPTER 7. SETS AND DICTIONARIES 19
7.2 Sets
Implement programs to:
1. Given two lists, for example [12, 13, 14, 14, 15, 16, 16], and [12, 13, 14], make
the following actions (use sets):
• Discover the elements that belong to both lists;
• Calculate the elements that are not common to both lists;
• Determine whether a set is superset or subset of another one.
2. Obtain the repeated elements of a list;
3. Given a large set of elements, build disjoint sets for each of equivalence
classes of those elements defined by the modulo operation. Example, two
elements, x, y are of the same class of equivalence if x%n == y%n.
4. ”The friend of my friend, my friend is”. Given a dictionary, where keys and
individuals and values are lists of friends, identify communities, disjoint
sets of friends of friends.