Lab2 PythonFirstSteps
Lab2 PythonFirstSteps
2. Data Types
<class 'str'>
type("3")
"3"enclosed in quotes, so it’s treated as a string.
<class 'float'>
type(3+1.5)
<class 'int'>
a = 10
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 This line creates a variable named width and assigns it the value
of 20.
>>> height = 5 * 9.3 This line creates another variable named height and assigns it
the result of the expression 5 * 9.3
>>>width * height 930.0 this line calculates the product of width and height.
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.
a=3
b=5
c=7
result = a - b // c
>>> 3
Interpretation:
Floor Division (b // c) 5//7>>>0
Subtraction (a - (b // c)) 3-0= 3
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!"
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:
Instructions:
Example Output:
if is_raining:
print("Stay indoors, it's raining.")
elif is_windy and temperature > 20:
print("Go for a walk, it's windy but warm.")
elif not is_windy and temperature > 10:
print("Go for a walk, the weather is fine.")
else:
print("Stay indoors, it's too cold.")