0% found this document useful (0 votes)
19 views

LAB #2 - Programming Techniques

Ejercicios básicos Python
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)
19 views

LAB #2 - Programming Techniques

Ejercicios básicos Python
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/ 4

LAB #2 - Exercises

1. Write a program that declares and multiplies two integer variables (4, 15), then print out the result on the screen.

Input: 4 and 15
Expected output:

The result is: 60

2. Check the type of different variables using the function type() .

Input:

a = 2
b = 3
c = a
char = 'a'
string_value = "hello"
bool_value = True
float_value = 2.3

Expected output:

<class 'int'>
<class 'int'>
<class 'int'>
<class 'str'>
<class 'str'>
<class 'bool'>
<class 'float'>

3. Which is the value of a ?

a = 2*3+1
print(a)
a = (2*3)+1
print(a)
a = 2* (3+1)
print (a)
a = 2*3**2+1
print(a)
a = 2*(3**2)+1
print (a)
a = (2*3)**2+1
print(a)

4. Write a program that asks the temperature in Farenheit and prints out the temperature in Celsius.

Input: 100

Expected output:

Temperature in Celsius is 37.77777777777778

5. Write a program to swap the values of two variables.

Input: a = 2, b = 3

Expected output:
a = 3 b = 2

6. Write a program to calculate the thermical sensation.

Input: t = 10.0, v = 5.0


Expected output:

Temperature = 10.0
Velocity = 5.0
Thermal sensation = 9.755115709161835

7. Write a program to calculate the values r and theta required to transform cartesian coordinates to polar. Use the functions
math.atan(x) and math.sqrt(x) :

Input: x = 2, y = 3

Expected output:

r = 3.605551275463989
theta = 0.982793723247329

8. Write a program that calculates the roots following the quadratic formula (Use the function math.sqrt(x) ):

Input: a = 4, b = 5, c = 1

Expected output:

The roots are:


-0.25
-1.0

9. Write and check the difference between 1/3 and 1//3?

1/3

1//3

10. Write and check the result of comparing 5 == "5".

5=="5"

11. Write a program to test the augmented assignment. What is the result of the following program?

a = 2
a += 3
print(a)
a *= 2
print(a)

12. Write a program to calculate the area of a circle of radius r. Use the constant math.pi

Input: r = 3

Expected output:
28.274333882308138

13. Write a program that asks the user for an integer numbers and prints out a message indicating whether the input is greater
than 10.

Input: 15
Expected output:

The input 15 is greater than 10.

14. Write a program that asks the user for two integer numbers and prints out the greater value.

Input: 4 and 15
Expected output:

The result is: 15

15. Write a program that asks the user for an integer number and prints the absolute value of the input value. Do not use the
built-in function abs()

Input: -3

Expected output:

The absolute value of -3 is 3.

16. Write a program that asks the user for an integer number, and prints out whether or not it is an even number.

Input: 4
Expected output:

4 is an even number.

17. Write a program that asks the user for a day number an prints the day name.

Input: between 1-7


Expected output:

Monday-Tuesday-etc.

18. Write a Program to extract each digit from an 3-digits integer in the reverse order :

Input: 753
Expected output:

3
5
7

19. Write a program to generate a diagram showing the facesof up to six dice (in 5 rows x 7 cols.):

Input: Select a number:


Expected output:
Select a number:3
-------
| * |
| * |
| * |
-------

Select a number:4
-------
| * * |
| |
| * * |
-------

20. Write a program that asks for a year and prints True if the year is a leap year, and False otherwise. In the Gregorian
calendar, a leap year follows these rules. Important: Do not use if and else keywords.
The year can be evenly divided by 4;
If the year can be evenly divided by 100, it is NOT a leap year, unless;
The year is also evenly divisible by 400. Then it is a leap year.

Input: 2020
Expected output:

The year 2020 is leap: True

Input: 2019
Expected output:

The year 2019 is leap: False

You might also like