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

null

The document outlines various programming tasks in Python, including calculating the hypotenuse of a right-angled triangle, finding areas of geometric shapes, converting temperatures, generating greetings, and checking for even or odd numbers. It provides sample code snippets for each task, demonstrating input handling and output generation. The tasks are aimed at practicing basic programming concepts and good coding practices.

Uploaded by

oluwajobaomoniyi
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)
2 views

null

The document outlines various programming tasks in Python, including calculating the hypotenuse of a right-angled triangle, finding areas of geometric shapes, converting temperatures, generating greetings, and checking for even or odd numbers. It provides sample code snippets for each task, demonstrating input handling and output generation. The tasks are aimed at practicing basic programming concepts and good coding practices.

Uploaded by

oluwajobaomoniyi
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/ 6

Untitled35

March 23, 2021

0.0.1 Write a program to calculate the hypotenuse of right angled triangle given the
lengths of its two sides. Use good programming practices in solving the problem

[1]: import math as m


length_1 = int(input("Enter the first length of triangle: "))
length_2 = int(input("Enter the second length of triangle: "))

h = m.pow(length_1,2) + m.pow(length_2,2)

hypotenus = m.sqrt(h)
print("The hypotenus of a right angled triangle: ", hypotenus)

Enter the first length of triangle: 3


Enter the second length of triangle: 4
The hypotenus of a right angled triangle: 5.0

0.1 Write a python program to solve each of the folowing problems:


0.1.1 (a) Input appropriate data and find the areas of the following
(i) a square

(ii) a triange

(iii) a circle

0.1.2 (b) convert temperature reading in degree Fahrenheit(F) to degree Centi-


grade(C)
0.1.3 (c) Input the name of a person and the time of the day and generate an appro-
priate greeting
0.1.4 (d) input the reg. no, name, dept, CGPA and other of a particular student and
generate an appropriate output to describe the student

[2]: import math as m


lenght =int(input("Enter the lenght of the square: "))
area = m.pow(lenght,2)
print("Area of square is: ", area)

1
Enter the lenght of the square: 4
Area of square is: 16.0

[3]: base = int(input("Enter the base of the triangle: "))


height = int(input("Enter the height of the triangle: "))

area = (1/2)*(base*height)
print("Area of a triangle is: ", area)

Enter the base of the triangle: 4


Enter the height of the triangle: 5
Area of a triangle is: 10.0

[4]: import math as m


radius = int(input("Enter the base of the triangle: "))

Area = m.pi * radius

print("Area of a circle is: ", Area)

Enter the base of the triangle: 5


Area of a circle is: 15.707963267948966

[5]: # C = (32F-32)*5/9

f = int(input("Enter the value for fahrenheit: "))

centigrade = ((32*f) - (32)) * (5/9)

print("Degree centigrade of the readings is ", centigrade)

Enter the value for fahrenheit: 20


Degree centigrade of the readings is 337.77777777777777

[7]: ## This code is calculating the scale in celsius if you are ask to write the␣
,→code to convert degree celsius to

## fahrenheit
celsius = int(input("Enter the value for celsius: "))

fahrenheit =(5/9) * celsius + 32

print("Degree fahrenheit of the readings is ",fahrenheit )

Enter the value for celsius: 0


Degree fahrenheit of the readings is 32.0

[8]: name = input("Enter your name: ")


time = input("Enter the time of the day")

2
print("Hello, ", name,",", " the time of the day is ", time,",", " you are␣
,→highly welcome to CSC201 class")

Enter your name: Abiodun Abayomi Oluwaseun


Enter the time of the day3:00pm
Hello, Abiodun Abayomi Oluwaseun , the time of the day is 3:00pm , you are
highly welcome to CSC201 class

[10]: name = input("Enter your name: ")


Reg_no = input("Enter your reg number: ")
department = input("Enter your department: ")
cgpa = input("Enter your current cgpa: ")

print("Hello i'm ", name, "with Reg number ", Reg_no,",", " am a student of ",␣
,→department, " with CGPA ", cgpa)

Enter your name: Abiodun Abayomi


Enter your reg number: MCB/2018/401
Enter your department: Microbiology
Enter your current cgpa: 5.0
Hello i'm Abiodun Abayomi with Reg number MCB/2018/401 , am a student of
Microbiology with CGPA 5.0

0.2 write a program that can ouput the even number between 1 to 40
[13]: ## using for loop

for i in range(2,40,2):
print(i)

2
4
6
8
10
12
14
16
18
20
22
24
26
28
30
32
34
36
38

3
[14]: ## with while loop

i = 2
while i<40:
print(i)
i = i+2

2
4
6
8
10
12
14
16
18
20
22
24
26
28
30
32
34
36
38

0.3 write a function that can print addition of the following numbers
0.4 (a) two numbers
0.5 (b) three numbers
0.6 (c) four numbers
[21]: def sum_of_two_num(a,b):
total = a+b
print(total)
sum_of_two_num(4,5)

[22]: def sum_of_three_num(a,b,c):


total = a+b+c
print(total)
sum_of_three_num(4,5,8)

17

4
[23]: def sum_of_four_num(a,b,c,d):
total = a+b+c+d
print(total)
sum_of_four_num(4,5,8,7)

24

0.7 Write a program to check the multiple of two and three between 1 to 50
using Aba and yomi and if none output Abayomi. The multiple of 2 will
output Aba and the multiple of 3 will output yomi
[24]: for i in range(1,50,1):
if i%2==0:
print("Aba")
elif i%3==0:
print("yomi")
else:
print("Abayomi")

Abayomi
Aba
yomi
Aba
Abayomi
Aba
Abayomi
Aba
yomi
Aba
Abayomi
Aba
Abayomi
Aba
yomi
Aba
Abayomi
Aba
Abayomi
Aba
yomi
Aba
Abayomi
Aba
Abayomi
Aba
yomi
Aba
Abayomi

5
Aba
Abayomi
Aba
yomi
Aba
Abayomi
Aba
Abayomi
Aba
yomi
Aba
Abayomi
Aba
Abayomi
Aba
yomi
Aba
Abayomi
Aba
Abayomi

0.8 Write a program to check if a number is even or odd


[25]: num = int(input("Enter any number: "))
if num%2==0:
print("The number is even")
else:
print("The number is odd")

Enter any number: 6


The number is even

[ ]:

You might also like