Tema 1_Introduction to Python Problems
Tema 1_Introduction to Python Problems
LEARNING OUTCOMES
• Employ conditional structures in Python to branch the behavior of a
software
• Employ looping structures in Python to repeat sequences or blocks
of actions
• Define functions in Python to encapsulate and organize code
• Describe the behavior of different types of data structures
• Employ appropriate data structures to create effective software
ARITHMETIC OPERATORS
1. Write a Python script that allows users to convert a given amount of money from
Euros to US Dollars. Both the amount of money and the exchange rate between Euros
and dollars should be input by the user using the keyboard.
2. Write a Python script to calculate the speed of a frictionless fluid at a given point, and
considering the information of the fluid at another point. More specifically, it will make
use of Bernouilli’s equation:
1 1
𝑃1 + 𝜌𝑣12 + 𝜌𝑔ℎ1 = 𝑃2 + 𝜌𝑣22 + 𝜌𝑔ℎ2
2 2
The user should input the pressure at both points, the fluid’s density, both heights,
and the speed at the initial point.
3. Write a Python script that allows users to solve second order equations (𝑎𝑥 2 + 𝑏𝑥 +
𝑐 = 0) by inputting values for coefficients of the second order equation. The script
should inform the user of available solutions, if any.
CONDITIONAL STRUCTURES
4. Write a Python script to determine if a given number is odd or even. The user should
input the number from keyboard.
5. Write a Python script that takes a year as input and determines whether it is a leap
year. A leap year is divisible by 100, but not by 100, unless it is divisible by 400.
6. Write a Python script to determine the amount of damage inflicted to an enemy in a
dungeon crawl board game. In the game, there are 3 classes: warrior, archer, and
mage. For each class, the damage calculation goes as follows:
• Warrior:
i. It depends on his/her strength and dexterity with the following
𝐷𝐸𝑋
formula: 𝐷𝑀𝐺 = 2 ∗ 𝑆𝑇𝑅 +
2
ii. If the warrior wields a two-handed weapon, the amount of damage is
modified by 1.5 factor.
• Archer:
i. The damage depends solely on the dexterity.
ii. If the archer equips elemental arrows, the damage is increased by 50.
iii. The final damage of the archer is reduced by distance, at a rate of 2
damage points per 10 meters.
• Mage:
i. The damage of the mage depends on intelligence and dexterity with
the following formula: 𝐷𝑀𝐺 = 𝐼𝑁𝑇 2 + 0.5 √𝐷𝐸𝑋
7. Write a Python script that allows users to calculate their mobile phone expenses if we
consider the following:
- For the first 120 minutes, the user pays at a rate of 0.03 € per minute.
- Then, up to 250 minutes the user pays at a rate of 0.05 € per minute.
- Finally, from that point onward, the user pays at a rate of 0.1 € per minute.
The user should input the monthly minutes consumed and the script should inform
about the amount to pay in the next bill.
LOOPING STRUCTURES
8. Write a Python script to determine if a given integer number (input from keyboard) is
prime.
9. Write a Python script to allow users to introduce temperature observations until
he/she introduces a special character. Then, the script should calculate the average of
the introduced observations.
10. Write a Python script to allow users to play a number-guessing name. The script should
randomly generate an integer number between 0 and 100. Then, the script should ask
numbers to the user until he/she guesses the randomly generated number. The
software should keep track of the number of attempts.
11. Write a Python script to read a string from keyboard and count the number of vowels
in the string.
12. Write a Python script that reads an integer n from keyboard. Then, the script will
generate and print n random lists of 10 elements with numbers from 0 to 1.
13. Write a Python script that generates two random lists of numbers with the same size
(10 elements) and creates a new list by adding both lists element by element.
14. Write a Python script that reads integer numbers from the keyboard until the user
introduces an odd number. Then, it should return the sum of all added elements.
FUNCTIONS