0% found this document useful (0 votes)
11 views2 pages

HCIA-AI Python Basics Exercises

Python Basics

Uploaded by

EDWIN
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)
11 views2 pages

HCIA-AI Python Basics Exercises

Python Basics

Uploaded by

EDWIN
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

HCIA-AI CERTIFICATION DAILY EXERCISE: PYTHON BASICS

1) Check the version of pandas and numpy installed using the following commands:
a) import numpy; print ([Link]) #numpy version
b) import pandas as pd; print (pd.__version__) #numpy version
2)
a) Write a program to print 'Hello HCIA-Huawei Team’
b) Write a program to define two variables, calculate their sum and display the results
3)
a) Write a program to define a tuple that contains only one element.
b) Write a program to define a tuple with five elements and then use the 'for loop' to print.
4) Define the variables x and y as lists of numbers, and z as a tuple.
x = [1, 2, 3, 4, 5], y = [11, 12, 13, 14, 15], z = (21, 22, 23, 24, 25)
a) What is the value of 3*x?
b) What is the value of x+y?
c) What is the value of x-y?
d) What is the value of x[1]?
e) What is the value of x[0]?
f) What is the value of x[-1]?
5) Write code to create a Python dictionary (the dict type) and print out the details. Add two entries to
the dictionary: Associate the key ‘name’ with the value ‘Reagan’, and associate the key ‘phone’
with ‘+254 722 222333’
6) Dictionaries:
a) Create a HCIA_AI dictionary (HCIA_AIdict), a data file listing members of this class and their
Counties
b) Create a dictionary entry for five members in the class, where the key is the name and the
value is the County.
c) Check the contents of your dictionary.
i) HCIA_AIdict.items()
ii) HCIA_AIdict.keys()
iii) HCIA_AIdict.values()
iv) HCIA_AIdict[‘Philip_Oyier']
v) ' Philip_Oyier ' in HCIA_AIdict
7) Strings:
a) Define the variable s as the string s=“We are on course with HCIA-AI Certification"
b) What is the value of 3*x? b) What is the value of x[1]? c) What is the value of x[-1]? d) What
is the value of x[::2]?
c) import string
text = “Huawei AI Bootcamp June 2025 "
i) print ("upper", "=>", [Link](text)), print ("lower", "=>", [Link](text))
ii) print ("split", "=>", [Link](text)), print ("join", "=>", [Link]([Link](text), "+"))
iii) print ("replace", "=>", [Link](text, “Comrades", “Students"))
iv) print ("find", "=>", [Link](text, “Comrades"), [Link](text, “Students"))
v) print ("count", "=>", [Link](text, "n"))
8) Conditional and Looping: Use a for/while loop to:
a) Print the numbers 0 to 100
b) Print the numbers 0 to 100 that are divisible by 7
c) Print the numbers 1 to 100 that are divisible by 5 but not by 3
9) Print for each of the numbers x = 2; : : : 20, all numbers that divide x, excluding 1 and x. Hence,
for 18, it should print 2 3 6 9.
a) Define a function to do Multiplication, such as Mul(8,6),and it output 42.
b) Complete the function definition so it returns the square of the product of the parameters, so
sqrProd(2, 5) returns (2*5)*(2*5) = 100.
def sqrProd(x, y):
10) Import numpy and then:
a) Use numpy to define an array, the shape of it is (5,5) and all elements of it is 0.
b) Create a 3x3 matrix with values ranging from 0 to 8
c) Find indices of non-zero elements from [1,2,0,0,4,0]
d) Create a 10x10 array with random values and find the minimum and maximum values
e) Create a random vector of size 30 and find the mean value
11) Write a Python program that prompts the user for two numbers, reads them in, and prints out the
product, labeled appropriately.
12) Complete the code for the following function so it matches its documentation:
def doubleList(numberList):
For each of the numbers in the list numberList, print a line containing twice the original
number. For example, doubleList ([3, 1, 5]) would print 6, 2, 10
13)
a) Create a Vehicle class with max_speed and mileage instance attributes. Create an instance of
the Vehicle class and use the following data with appropriate methods to read and display the
values (max_speed: 240 km/hr, mileage: 10,000 km)
b) Create child class Bus that will inherit all of the variables and methods of the Vehicle class,
and has name attribute. Use the following data to test your class; Name: "School Mercedes",
max_speed = 180, mileage = 1000. Test and display members of Bus class
c) Create a Bus class that inherits from the Vehicle class. Add an attribute the seating_capacity
and give the argument of Bus.seating_capacity() a default value of 50.
d) Define a class attribute”color” with a default value white. i.e., Every Vehicle should be white.
Test and display members of both the Vehicle and Bus classes

You might also like