/logica-de-programacao

A repository for programming logic!

Primary LanguagePython

Python

Python is a great language to start program. Your syntax is clean and easy to understand.

Python!

Summary

List 1

Back to top

1. Make a Program that shows the message "Hello world" on the screen.

2. Make a Program that asks for a number and then displays the message "The number entered was {number}".

3. Make a Program that asks for two numbers and shows the sum between them.

4. Make a Program that asks for four numbers and shows the average.

5. Make a Program that converts meters to centimeters.

6. Make a Program that asks for the radius of a circle, calculate and show its area.

7. Make a program that calculates the area of a square and shows twice that area for the of the user.

8. Make a program that asks how much you earn per hour and the number of hours worked in the month. Calculate and show your total salary for that month.

9. Make a program that requests the temperature in degrees Fahrenheit, transform and show the temperature in degrees Celsius. (C = (5 * (F-32) / 9)).

10. Make a Program that asks for the temperature in degrees Celsius and converts it to degrees Fahrenheit.

List 2

Back to top

1. Make a program that compares two numbers and prints the largest one.

2. Make a Program that asks for a value and shows on the screen whether the value is positive or negative.

3. Make a program that checks if a typed letter is "F" or "M". As the letter writes: F - Female, M - Male. If you do not enter any of the options display an error message.

4. Make a Program that checks if a typed letter is a vowel or consonant.

5. Make a program to read a student's two partial grades. The program should calculate the average achieved per student and present:

a) The message "Approved", if the average achieved is greater than or equal to seven;

b) The message "Reproved", if the average is less than seven;

c) The message "Approved with Distinction", if the average is equal to ten;

6. Make a Program that reads three numbers and shows the biggest one.

7. Make a Program that reads three numbers and shows the biggest and the smallest of them.

8. Make a program that asks the price of three products and show you which product you should buy, knowing that the decision is always for the cheapest.

9. Make a Program that reads three numbers and shows them in descending order.

10. Make a Program that asks in which shift you study. Ask to type M - morning or A - afternoon or N - night. Print the message "Good morning!", "Good afternoon!" or good night!" or "Invalid Value!", as appropriate.

List 3

Back to top

1. Make a program for the calculation of a payroll, knowing that the discounts are from the Income Tax, which depends on the gross salary (as shown in the table below) and 3% for the Union and that the FGTS corresponds to 11% of the salary gross. The Net Salary corresponds to the Gross Salary less discounts. The program should ask the user for the value of their hour and the number of hours worked in the month.

  • Income Tax Discount:
    • Gross salary up to 900 (inclusive) - exempt
    • Gross Salary up to 1500 (inclusive) - 5% discount
    • Gross Salary up to 2500 (inclusive) - 10% discount
    • Gross Salary above 2500 - 20% discount

2. Make a Program that reads a number and displays the corresponding day of the week. If you enter another value, it should be shown: 'invalid value'. Consider that the month starts on Sunday.

3. Make a program that reads two values obtained by a student in a discipline over the course of a semester, and calculate their average. The attribution of concepts follows the table below:

  • Average Utilization | Concept
    • Between 9.0 and 10.0 => A
    • Between 7.5 and 9.0 => B
    • Between 6.0 and 7.5 => C
    • Between 4.0 and 6.0 => D
    • Between 4.0 and zero => E

The algorithm must show on the screen the grades, the average, the corresponding concept and the message “APPROVED” if the concept is A, B or C or “FAILED” if the concept is D or E.

4. Make a Program that asks for the 3 sides of a triangle. The program should inform if the values can be a triangle. Indicate, if the sides form a triangle, if it is: equilateral, isosceles or scalene.

  • Tips:
    • Three sides form a triangle when the sum of any two sides is greater than the third;
    • Types of Triangle:
      Equilateral Triangle: three equal sides;
      Isosceles Triangle: any two equal sides;
      Scalene Triangle: three different sides;

5. Make a program that calculates the roots of a second degree equation, in the form ax2 + bx + c. The program should ask for the values ​​of a, b and c and make the calc, informing the user in the following situations:

  • If the user reports the value of A equal to zero, the equation is not of the second degree and the program should not ask for the other values, being closed;
  • If the calculated delta is negative, the equation has no real roots. Inform the user and close the program;
  • If the calculated delta is equal to zero, the equation has only one real root; inform the user;
  • If the delta is positive, the equation has two real roots; inform the user;

List 4

Back to top

1. Make a program that asks for enter a value between zero and ten. Show a message if the value is invalid and keep asking until the user enters a valid value.

2. Make a program that reads a username and password and verify if the username is equal of password. If this happen, show an error and asking for the information again.

3. Make a program that read and valid theses information:

Name: bigger than 3 characters;
Age: between 0 and 150;
Salary: bigger than 0;
Genre: M for Man and W for Woman;
Marital Status: S (single), M (married), W (widower), D (divorced);

4. Assuming that the population of country A is of the order of 80,000 inhabitants with an annual growth rate of 3% and that the population of B is 200,000 inhabitants with a growth rate of 1.5%. Make a program that calculates and writes the number of years needed for the population of country A to exceed or equal the population of country B, while maintaining growth rates.

5. Change the previous program allowing the user to inform the populations and the initial growth rates. Validate the entry and allow the operation to be repeated.

6. Make a program that prints the numbers from 1 to 20, one below the other. Then modify the program so that it shows the numbers next to each other.

7. Make a program that read 5 numbers and shows the biggest.

8. Make a program that reads 5 numbers and gives a sum and an average of the numbers.

9. Make a program that prints on the screen only the odd numbers between 1 and 50.

10. Make a program that receives two integer numbers and generates the integer numbers which are in the range between them.

List 5

Back to top

1. Make a program that asks for two numbers, base and exponent, calculate and show the first number raised to the second number. Do not use the language power function.

2. Make a program that asks for 10 integer numbers, calculate and show the number of even numbers and the number of odd numbers.

3. Make a program that calculates the factorial of an integer provided by the user.
Example: 5! = 5 * 4 * 3 * 2 * 1 = 120

List 6

Back to top

1. Make a program that reads a vector of 5 integer numbers and shows them.

2. Make a program that reads a vector of 10 real numbers and shows them in reverse order.

3. Make a program that reads 4 notes, shows the notes and the average on the screen.

4. Make a program that reads a 10 character vector and tells you how many consonants were saved. Print as consonants.

5. Make a program that reads 20 integgernumbers and stores them in a vector. Store the even numbers in the even vector and the odd numbers in the odd vector. Print the three vectors.