0% found this document useful (0 votes)
6 views4 pages

CSC201 PRACTICAL - Print TH-WPS Office-1

The document contains Python code snippets demonstrating input/output statements and functions including printing current timezones in Africa, printing current date and time, displaying a calendar for a given year, calculating area of a triangle given base and height, and adding two numbers and printing the output.

Uploaded by

olusesiisrael93
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views4 pages

CSC201 PRACTICAL - Print TH-WPS Office-1

The document contains Python code snippets demonstrating input/output statements and functions including printing current timezones in Africa, printing current date and time, displaying a calendar for a given year, calculating area of a triangle given base and height, and adding two numbers and printing the output.

Uploaded by

olusesiisrael93
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

CSC 201 PRACTICAL WORK.

USING INPUT AND OUTPUT STATEMENT/FUNCTION

1#####.Print the current timezones in Africa

from datetime import datetime

import pytz

# Set the timezone to Africa/Lagos

tz = pytz.timezone('Africa/Lagos')

# Get the current time in the specified timezone

current_time = datetime.now(tz)

# Print the current time and date in Africa/Lagos timezone

print("Current time in Africa/Lagos:", current_time.strftime('%Y-%m-%d %H:%M:%S'))

2#### python code to print the current time

import datetime

now = datetime.datetime.now()

print("Current date and time:")

print(now.strftime("%Y-%m-%d %H:%M:%S"))

print("Current year:")

print(now.year)

3##### Here is a Python code to display the calendar for the year 2024 using the `calendar` module:

```python
import calendar

year = 2024

# Create a TextCalendar object

cal = calendar.TextCalendar(calendar.SUNDAY)

# Display the calendar for the year 2024

for month in range(1, 13):

print(cal.formatmonth(year, month))

```

When you run this code, it will display the calendar for each month in the year 2024. Each month is
displayed in a grid format with the days of the week and dates listed.

4#### Here is a Python code snippet to calculate the area of a triangle given its base and height:

To calculate the area of a triangle given its base and height, you can use the formula:

area = 0.5 * base * height

Here is the Python code snippet to calculate the area of a triangle with a base of 25 and a height of 16:

```python

base = 25

height = 16

area = 0.5 * base * height


print(f"The area of the triangle with base {base} and height {height} is: {area}")

```

When you run this code, it will output:

```

The area of the triangle with base 25 and height 16 is: 200.0

```

Therefore, the area of the triangle with a base of 25 and a height of 16 is 200 square units.

5#### write a python program to add two numbers and print the output

Here is a simple Python code that adds two numbers and prints the output:

```python

# Input the two numbers

num1 = 10

num2 = 20

# Add the two numbers

sum = num1 + num2

# Print the output


print("The sum of", num1, "and", num2, "is", sum)

```

In this code, we input two numbers (10 and 20 in this case), add them together, and then print the sum.
You can change the values of `num1` and `num2` to add any two numbers you like.

You might also like