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

Lab2 PythonFirstSteps

test

Uploaded by

ophiliafa18
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)
4 views

Lab2 PythonFirstSteps

test

Uploaded by

ophiliafa18
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/ 3

ENSA-Kenitra Module : Compétence Numériques

LAB 2 : Python First Steps


1. First Python commands

Instruction to type Result obtained + comment or explanation


20+1

20/3

20//3

20%3

5.45*10

2**4

(3+2)*5

3+2*5

result = 3 + 5 * 2 ** 3 - 4 / 2
print(result)

result = (10 + 5) * 3 - 8 / 2 ** 2 + 1
print(result)

2. Data Types

Instruction to type Result obtained + comment or explanation


type(3)

type(1.5)

type(3.0)

type("bonjour")

type("3")

type(3+1.5)

a = 10

print(type(a))

Pr. Mehdia AJANA Chapter2 – Python First Steps 1


ENSA-Kenitra Module : Compétence Numériques

b = 3.14
print(type(b))
c = True
print(type(c))

d = "Python"
print(type(d))
a = input("Enter your
height: ")
print(type(a))
a = float(input("Enter
your height: "))
print(type(a))

Exercises :

1. Write a script that asks the user for the day, month, and year, then displays the date as
follows:
Today’s Date is : 12/12/2023.

2. Describe what happens in each of the three lines of the example below:
>>> width = 20
>>>height = 5 * 9.3
>>>width * height
930.0
3. Assign the respective values 3, 5, and 7 to three variables a, b, c.
Perform the operation a - b // c.
Interpret the obtained result.

4. Change your script by asking the user to enter the three variables’ values, and then
display their types and the operation result.

5. Write a Python program that takes a student's score as input and outputs the
corresponding grade based on the following grading scale:
Score ≥ 90: Grade A
Score 80-89: Grade B
Score 70-79: Grade C
Score 60-69: Grade D
Score < 60: Grade F

Ensure that the input is valid (i.e., the score should be between 0 and 100).
If the input is invalid, print an error message like "Invalid score!"

Pr. Mehdia AJANA Chapter2 – Python First Steps 2


ENSA-Kenitra Module : Compétence Numériques

6. Weather Decision System: Write a Python program that asks the user to input the
current weather conditions and decides whether a person should go for a walk based on
the following:

 If it's raining, the person should stay indoors.


 If it's windy but not raining, the person should only go for a walk if the
temperature is above 20°C. Otherwise, they should stay indoors.
 If it's neither raining nor windy, the person should go for a walk if the
temperature is above 10°C. Otherwise, they should stay indoors because it's too
cold.

Instructions:

 Ask the user for weather input:


o is it raining? (True/False)?
o is it windy? (True/False)
o What is the temperature?

Example Output:

 "Stay indoors, it's raining."


 "Go for a walk, it's windy but warm."
 "Go for a walk, the weather is fine."
 …

Pr. Mehdia AJANA Chapter2 – Python First Steps 3

You might also like