0% found this document useful (0 votes)
5 views9 pages

L4- Problems

The document outlines a series of programming problems focused on Python conditionals, ranging from basic input validation to more complex calculations involving salaries, grades, and currency exchange. Each problem includes specific requirements and expected outputs, with some marked as assessable and others as optional. The problems are designed to progressively build programming skills in Python through practical applications.

Uploaded by

tanqueray
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)
5 views9 pages

L4- Problems

The document outlines a series of programming problems focused on Python conditionals, ranging from basic input validation to more complex calculations involving salaries, grades, and currency exchange. Each problem includes specific requirements and expected outputs, with some marked as assessable and others as optional. The problems are designed to progressively build programming skills in Python through practical applications.

Uploaded by

tanqueray
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/ 9

Informatics 1

PROBLEMS - Lesson 4: Python Conditionals

Problems in yellow → Assessable problems (evaluable)


The rest of the problems are of intermediate difficulty. If you have any difficulty moving
from one recommended problem to the next one, do some of the problems that appear
in between for more progressive learning.
Problems in blue → Optional problems (not assessable).

Problem 1
Make a program that reads an integer from the keyboard and checks if the value is in
the range [0.10]. If the number is in the range, the program must display the message:
"Number XX is in the interval."
where XX is a number entered by the user. Otherwise, the program must show:
"Number XX is NOT in the interval."

Problem 2
Make a program that reads the time of a clock and writes the time increased by a second.
The reading and writing of the hours must be in the following format: 05:23:52, which
means that hours, minutes, and seconds with two digits and separated by a colon (:).
Make a first version of the program that only does:
• Reading hours, minutes, and seconds
• Writing the same time in the established format
Then, just after reading the time, add this step:
• Increase the time by 1 second, checking that if it reaches 60 seconds, the minutes
must be increased by 1. If it reaches 60 minutes, the hour must be increased by
1, and if the hour reaches 24, you need to set the hours to 0.

Problem 3
Make a program that asks for a number and displays the message "Positive" if the input
is a positive number (including 0) or displays the message "Negative" otherwise.

Problem 4
Make a program that reads a character via keyboard and outputs the string "Vowel" if it
is a vowel or "Consonant" if it is a consonant. Suppose the user always enters a letter.

Problem 5
Make a program that reads an integer and tells us if it is positive, negative or zero with
the messages "Positive", "Negative" or "Zero".
Problem 6

1
Informatics 2

Make a program that calculates the final salary of a worker. The program will ask for the
base salary in euros (float) and seniority in years (int). The program will calculate the
final salary as the base salary plus a value that is calculated as a percentage of the base
salary according to the employee's seniority:
- Less than 3 years old: 1% increase in base salary
- Between 3 and 5 years of seniority: 2% increase on the base salary
- More than 5 years old: an increase of 3.5% on the base salary
The program will announce the new salary of the worker with the message: "The final
salary is: XX" where XX is a real number (salary).

Problem 7
Make a program that implements a menu of three options. The program should display
the menu options and ask you to choose one of the options:
Menu
1 - Option 1
2 - Option 2
3 - Option 3
Select the option:

Once the user has indicated one of the options, the program will display a message
indicating that the task corresponding to the menu option is being done. These messages
will be formatted as: "Doing task X", where X will be an integer and will correspond to the
selected menu option (1, 2 or 3).

If the user selects a task different than 1, 2, and 3, the program will display the following
error message: "Incorrect option"

Problem 8
Make a program that reads a character from the keyboard. First, the program will check
whether it is a letter ("a", ..., "z") or ("A", ..., "Z"). In this is not the case, the program must
say that the character is not allowed with the message "Character not allowed".
In case it is a letter, the program must say whether it is vowel or consonant in uppercase
or lowercase with the corresponding message ("Vowel in lowercase", "Vowel in
uppercase", "Consonant in lowercase" or "Consonant in uppercase").

Problem 9
Make a program that reads via keyboard the year of a person's birth and calculates the
person's age in 2025. Then it will show the age of the person on the screen. The format
of the message should be: "You will be XX years old in 2025." where XX is a number.
Also, if the person is of legal age, the program should indicate this on the next line with
the message "You will be in legal age."

Problem 10

2
Informatics 3

Make a program that reads via keyboard the year of a person's birth and calculates the
person's age in 2025. Then it will show the age of the person on the screen. The format
of the message should be: "You will be XX years old in 2025." where XX is a number.
Also, if the person is in working age, the program should indicate this on the next line
with the message "You will be in working age."
Note: A person is in working age if he/she is over 16 (included), and under 67.

Problem 11
Make a problem that calculates the perimeter of a square. The program should read the
value of the side and check that it is a positive value. The calculation of the perimeter
will only be done only if this condition is met.

Problem 12
Make a program that asks the user to write two numbers and sorts them from lowest to
highest. The “num1” variable will contain the first number, and "num2" variable the
second number. If the first number is greater than the second one, the values of the two
numerical variables must be exchanged so that "num1" contains the smallest value and
"num2" the largest value. Finally, the program should print the result with a formatted
message: "The value of num1 is <num1> and the value of num2 is <num2>" where
<num1> and <num2> are the values of the variables "num1" and "num2" respectively.

Problem 13
Make a program that reads an integer and writes its absolute value.

Problem 14
Make a program that reads the year of a person's birth and calculates the person's age
in 2025. From the age, the program must determine whether the person is a minor or an
adult. The output of the program will be a message in the format "You will be XX years
old in 2025 and you will be a minor." if the person is a minor, or "You will be XX years
old in 2025 and you will be an adult." if the person is in legal age. In both cases, XX is
the age of the person.
Note: A person is of legal age if the age is equal or above 18.

Problem 15
Make a problem that calculates the area and perimeter of a circle. The program should
ask for the value of the radius and check that it is a positive value. The calculation of the
area and perimeter will only be done if this condition is met. If not, an error message will
be displayed.

Problem 16

3
Informatics 4

Make a program that asks the user to enter an integer number and prints the message
"EVEN" if it is an even number or "ODD" otherwise. Remember that an integer n is even
if its modulus 2 is zero, that is, if (n% 2) == 0 is a true expression.

Problem 17
Make a program that reads via keyboard a year and tells us if February has 28 or 29
days in that year. February has 29 days in leap years. A leap year is a multiple of 4 but
not 100, or if it is a multiple of 400.
If leap year, the program will output the message "In XX February has 29 days." where
XX is the year introduced via keyboard. Otherwise, the message will be " In XX February
has 28 days."

Problem 18
We want to modify the age calculation program so that, in addition to calculating the age
of the user in 2025 from his year of birth, it tells you if he/she is older or younger with the
corresponding message ("You will be XX years old in 2025 and you will be a minor. "Or"
You will be XX years old in 2025 and you will be an adult.").
If the user is in legal age, the program will inform if the person is in retirement age with
a message "You are of retirement age."
Note: The retirement age is 67 years.

Problem 19
We want to modify the age calculation program so that, in addition to calculating the age
of the user in 2025 from his year of birth, it tells if the user is older or younger with the
corresponding message ("You will be XX years old in 2025 and you will be a minor." or
"You will be XX years old in 2025 and you will be an adult.").
In addition, if the user is a minor, we want to check if the person has finished primary
school ("You will have finished primary.") or not ("You will have not finished primary yet.").
If the user will be in legal age, we want to know if the user will be in working age ("You
will be in working age.") or in retirement age ("You will be in retirement age.").
Note: Primary schooling ends at the age of 12 and the retirement age is 67 years.

Problem 20
Make a program that asks the user to enter three numbers and determine if the sum of
any pairs of them is equal to the other number. If this condition is met write "EQUAL";
otherwise, type "DIFFERENT".

Problem 21
Given the following definition of variables in pseudocode:

4
Informatics 5

var
Day: char; /* M:monday, T:tuesday, X:wednesday, H:thursday, F:friday, S:saturday,
U:sunday */
Month: integer; /* values from 1 up to 12 */
endvar
Make a program that reads one day and month and checks if the day stored in the
variables is a holiday or not. We will assume that, in our company, the weekends, all
days in August and all Fridays of July are holidays. The program must also check that
the day and month are valid values and, if not, output an error message.

Problem 22
Implement a program that allows you to make the invoice for the sale of several units of
the same product. The number of units sold and the price of the product should be read
by keyboard. A 7% VAT must be applied to the resulting price. If the final amount, after
applying VAT, is above 500 euros, a 5% discount will be made. If it is above 1000 euros,
then a 10% discount will be made. The program must show the final price of the purchase
with a message: "The final amount of the purchase is XX euros." where XX will be a real
number.

Problem 23
Make a program that prints the diagnosis of patients depending on their cholesterol level.
The program will ask for the patient's cholesterol level, which will be an integer value.
The message will be given according to the following specification:
• “Error” if the value is negative.
• “Correct” if the amount is less than 200mg / dl.
• “Needs diet” if the amount is between 200mg / dl. and 240mg / dl.
• “Need medication” if the amount is greater than 240mg / dl.

Problem 24
Implement a program that asks for the value of a worker’s salary and writes a message
with the personal income tax withholding rate (IRPF) to be applied. This percentage
depends on the income according to the following table:
• 0% if salary is under <= € 25,000
• 15% if € 25,000 < salary <= € 40,000
• 20% if € 40,000 < salary <= € 100,000
• 30% if salary > € 100,000

The program will indicate the withholding percentage with a message with the format:
"The withholding tax rate (IRPF) is XX%" where XX will be an integer.

Problem 25

5
Informatics 6

Make a program that calculates the final grade of a subject. The program should ask the
user to enter their Theory, Seminar and Practice mark (in this order) and calculate the
final numerical mark according to the formula:
Final Grade = 0.4 x Theory + 0.3 x Seminars + 0.3 x Practices
Once the numerical mark has been calculated, the program must output the grade in the
academic record, according to the following criteria:
Fail mark in the interval [0,5)
C mark in the interval [5,7)
B mark in the interval [7,9)
A mark in the interval [9,10)
A with honors mark is 10
The program will indicate the final grade with a message in the format: "The final grade
is NN - XXXXXX" where NN will be the numerical mark and XXXXXX will be the grade
in the academic record.

Problem 26
Make a program that calculates the change that a beverage vending machine must
make. The machine accepts and exchanges 2 and 1 euro coins and 50, 20, 10 and 5
cents. The program must ask for the amount of the drink we want to buy and the amount
of money we put into the machine. You must calculate the exchange rate and write the
minimum number of coins of each type (2, 1, 0.50, 0.20, 0.10 and 0.05 euros) that the
machine must return to us.

Problem 27
Implement a program that reads four integers and then writes the highest of the four,
using as few comparisons as possible and without using any auxiliary variables. The
output message should follow the format: "The highest number in the series is NN.
Comparisons: XX" where NN and XX are two integers.

Problem 28
Make a program that reads three integer numbers and identifies the maximum, and the
minimum, using as few comparisons as possible.

Problem 29
Make a program that calculates the grade of the subject Programming. The program will
ask for the notes of continuous assessment, practice and individual assessment (in this
order) and will display a message with the final grade: "The final grade of the block is
XX" where XX will be the numerical value of the grade of the block. The evaluation of the
subject is:
Mark = (0.1 * Problems) + (0.3 * Practice) + (0.6 * Individual Exam)

Conditions:

6
Informatics 7

• Problems >=5
• Pràctice >=5
• Individual Exam >=5
If the subject is failed for not reaching the minimum of 5 in any of the three parts, the final
grade will be the lower value of the result of applying the formula and 4.
Note: The grade "Not Evaluable" will be represented by the value -1 if a student has not
done the practice or individual exam, so the user will enter -1 when the program asks for
the grade. In case of not doing the problems, the assessment will be counted as a zero.

Problem 30
Make a program that asks the user to enter an integer between 1 and 7 via keyboard
and print the day of the week that corresponds to 1 = "MONDAY", 2 = "TUESDAY", 3 =
"WEDNESDAY", 4 = "THURSDAY", 5 = "FRIDAY", 6 = "SATURDAY", 7 = "SUNDAY").
Otherwise, it prints the error message "THE NUMBER ENTERED DOES NOT
CORRESPOND TO ANY DAY OF THE WEEK"

Problem 31
Implement a currency exchange program. The program will ask for an amount expressed
in € and then the option corresponding to the currency selected to make the change
(1-Dollars (USD), 2-Pounds (GBP), 3-Swiss Francs (CHF), 4-Yens JPY)).
The program will show the result of making the change to the requested currency with a
message:
"XX euros are YY ZZZ"
where XX is the amount of euros to change, YY is the amount in the requested currency
and ZZZ is the corresponding currency code (USD, GBP, CHF, JPY). If the user selects
a non-existent option, the program will output an error message: "Error: currency not
available".
Note: The change will be: 1 € = 1.34 USD = 0.83 GBP = 1.23 CHF = 133.11 JPY

Problem 32
Make a program that asks the user to enter an integer corresponding to the group
number and print the classroom assigned to that group with a message with the format:
“Classroom assigned to group XX: YYYYY” where XX will be the number of the group
entered by the user and YYYYY will be the classroom assigned to the group. If the group
number is incorrect (41,43,45,47,51,52) the procedure must print an error message:
"Error: group does not exist"
Classroom assignment:
• Group 41 - Q8 / 2021
• Group 43 - Q5 / 2033
• Group 45 and Group 51 - Q9 / 1055
• Group 47 and Group 52 - Q9 / 3077

Problem 33

7
Informatics 8

Make a program that allows us to know our sign of the Chinese zodiac. The program will
ask us to enter the year of birth and then it will display the message "Sign: XXXX" where
XXXX will be our sign in the Chinese zodiac.
The signs of the Chinese zodiac are determined from the result of calculating the result
of the year module 12: 0 = "monkey", 1 = "rooster", 2 = "dog", 3 = "pig", 4 = rat”, 5 =“ox”,
6 =“tiger”, 7 =“rabbit”, 8 =“dragon”, 9 =“snake”, 10 =“horse”, 11 =“goat”.

Problem 34
In a restaurant, all orders are noted with a tablet and the dishes on the menu are coded
with a character. Implement a program that allows you to make a conversion on the
kitchen screen. The program will read the character corresponding to the dish to be
ordered and must print on the screen its equivalence:
B = "Burger", F = "French Fries", P = "Pizza" and S = "Sandwich"
The procedure must tolerate both uppercase and lowercase characters.

Problem 35
Make a program that translates vowels into the Morse language. The program should
prompt the user to enter a vowel and return the corresponding Morse code according to
the table:

VOWEL A E I O U
MORSE .- . .. --- ..-

The conversion must be displayed with a message in the following format:


"Vowel: X - Morse code: YYY"
where X is the vowel entered by the user and YYY is the corresponding Morse code. If
any character other than a vowel (lowercase or uppercase) is entered, the program must
show an error message:
"Error: The input character is not a vowel."

Problem 36
Make a program that reads a date in DD / MM / YYYY format where DD is the day, MM
is the month and YYYY is the year. The program must tell if the date is correct or not.
Follow these steps:
a) Make a first program that reads a number corresponding to the month of the date
(from 1 to 12) and writes the number of days in that month (assuming that February
always has 28 days). If the month number is incorrect, an error message should be
displayed: "Error: Incorrect month".
b) Make a second program that reads the value corresponding to a year and tells if
February has 28 or 29 days in that year. Remember that February has 29 days in
leap years and a leap year is a multiple of 4 but not 100 or if it is a multiple of 400.
c) Make a third program that reads a value corresponding to the day of a date and the
number of days in a given month. The program should tell if the value of the day is
correct for that month (“Correct Date”) or not (“Error: Incorrect Day”). For example, if

8
Informatics 9

the value of the day is 31 and the number of days in the month is 30, the value of the
day is incorrect.
d) Make a new complete program by merging the three previous programs into one.

Problem 37
Make a program that implements a basic calculator of operations with real numbers. The
program should display a small menu with five options (addition, subtraction,
multiplication, division, and exit):
MENU
1.- Addition
2.- Subtraction
3.- Multiplication
4.- Division
5.- Exit
Select one option:
The user will select the operation via keyboard by writing the corresponding number. The
program must then ask the user to enter the two operands and perform the
corresponding operation. You must then display the result of the operation on the screen
in a format like the following example: "6 + 8 = 14". Use the symbols: +, -, *, : for
operations.
In case of selecting the division, it is necessary to control that a division by zero does not
take place. If the second operand is zero, an error message will be displayed: "Error:
Division by Zero".
If the exit operation is selected, the program should display the message "Exiting the
calculator..." and finish.
If an option that is not in the menu is entered, the program should display an error
message: "Error: Invalid option" and exit.

You might also like