Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

Department of Computer Science

Iqra University, Karachi

ARTIFCIAL INTELLIGENCE LAB


Assignment 1:(CONTROL STRUCTURES AND LOOPING
UNDERSTANDING,PYTHON MODULES, LAMBDA,ARRAYS,FILING)

1 Read it first
Prior to start solving the problems in this assignments, please give full concentration on following
points.

1. graded assignment — yes


2. go in details. Comprehensive work required, it means your solution must be detail oriented.
But, it doesn’t mean decoration of your assignment.
3. “First, solve the problem. Then write the code”, John Johnson
4. don’t cheat – you’ll get straight forward zero.
5. This is the individual assignment if you are stuck in a problem contact your teacher/ Co-
teacher, but in the mean time start solving the next question (don’t waste time).
6. This assignment contain 3 section: 1st is pseudocode 2st is Awesomeness

1-PSEUDOCODE & SCENERIO


Understand the pseudo codes below and convert it into PYTHON PROGRAM accordingly.
1. Suppose you have to make a program for your granny; who, due to her advanced age, is ableto
do calculations, not even a simple division. She got a package which contains 90 candies, and
she wants to distribute it among her all grandchildren. She has 5 grandchildren, among them 3
are the granddaughters. She wants to distribute candies such as a granddaughter gets twice
candies as gets by a grandson. Consider following pseudo code:
1. Start
2. numOfGrandChildren ← 5
3. numOfGrandDaughters ← 3
4. numOfGrandSons ← (numOfGrandChildren - numOfGrandDaughters)
5. candies ← 90
6. [Comment: Since grand-daughter will get twice of candies therefore]
7. receivers ← (numOfGrandDaughters * 2) + numOfGrandSons
8. candiesPerChild ← candies / receivers
9. print "Candies/grand-daughter" + (candiesPerChild * 2)
10. print "Candies/grand-son" + (candiesPerChild * 1)

Designed By : Hira Farman


2. Hira Farman is thinking about calculating the weighted scores for the assignmentsand
examination in this semester. He says every assignment and exam should have a certain
weights and thus, the total score is given on the basis of the respective weights. Let’s assume,
he gives 3 assignments and 2 exams, each with maximum score of 100 points. And, he sets the
weights for all assignments to 10% and the weights for the exams to 35%.
1. Start
2. print "Please enter score for assignment 1"02. as1 ← read input
03. print "Please enter score for assignment 2" 04. as2 ← read input
5. print "Please enter score for assignment 3"
6. as3 ← read input
7. print "Please enter score for exam 1"08. ex1 ← read input
9. print "Please enter score for exam 2"
10. ex2 ← read input
11. [Comment: since 10% is 0.1 and 35% is 0.35]
12. weightedScore ← (as1 + as2 + as3)*0.1 + (ex1 + ex2)*0.35
13. print "Weighted Score is " + weightedScore
14. end

3. In a Software house, employer efficiency is determined on the basis of time required for a
employer to complete a particular job. If the time taken by the employer is between 2-3
hours,then the employer is said to be highly efficient. If the time required by the employer is
between 3 -4 hours, then the employer is ordered to improve speed. If the time taken is
between 4-5 hours, the employer is given training to improve his speed and if the time taken
by the employer is more than 5 hours, then the employer has to leave the company . If the
time taken by the employer is input through the keyboard, find the efficiency of the employer.

4. You are asked to compute weekly payment for an employee working at CubixLabs.
TheCubixLabs has a policy such that, if the employee works less than 50 hours in a week then
he/she will get payment as per the given payment rate, that is amount per hour. Otherwise (in
all other conditions) he/she will get payment which is 50 × payment rate.

5. You have to write a program that will take two numbers and a mathematical operator (+, -, * or
/) as the input from the user. Then, you have to perform user-given mathematical operation on
input numbers. Consider following pseudo codes:

6. You have to ask a word w from user, and a number n. You have to print that word upto n time.
Suppose, user enters the word ‘Pakistan’ and number 10, then your program should print the
word ‘Pakistan’ ten times. Yes, the smartest way to deal with this kind of problem is to use a
repeating structure.

7. You have to print the sum of numbers that are in a user defined range. For it you have to ask
the lower bound (limit) and upper bound of a numerical range, and then set an identifier sum
to zero. Then, implement a repeating structure that will add, one by one, all number coming
within user defined range. Remember, adding up a number should retain the value of all
previous summations.

Designed By : Hira Farman


8. The program is made for deciding either a candidate who is applying for Pakistan armed forces
is eligible or not. An eligible candidate must fulfil all necessary conditions as give in the
following criteria:
Criterion Value
Nationality Pakistani or AJK
Age Between 18-22, boundaries are inclusive
Education minimum 14 years
Table 3.1: Criteria for Pakistani armed forces eligibility

9. Ask a number from user and add next number to it. The process of addition should be repeated
until the sum would become 100 or greater. In the case where user enters the number ≥ 100,
the program should be stopped. In between the steps, you have to count how many iterations
it took for attaining the sum equals to 100.
10. You have to take two numbers as an input from user; and print their average if both inputs
are positive, otherwise print the product of numbers.

f(input1, input2)

11. You are to find mid of two points P and Q. Each point is consisting of two coordinates (x and
y). Seek the values of P and Q from user. Mid-point formula can be:

12. Write a program where you have to ask road type and speed of the vehicle from user and
then decide whether a car is over-speeding, is under-speed or it is moving with the allowed
speed. The allowed speed limit is given in the following table. See the following conditions:

Road Type Speed Limit


Local Street 20-30 km/h
Main Street 31-40 km/h
Main Road 41-90 km/h
High way 91-110 km/h
Table 4.1: Normal (Allowed) Speed criteria

13. Bundoo khan is famous restaurant in Karachi, they have almost manual process. Now they are
willing to use computers and need a computer program that helps them to process their
orders. They defined their process as: When a user comes and asks about deals, we replied we
have three deals for as per different budget and our deals are associated with days. Often we
have complementary food to our customers. You have to workout a solution that asks user to
enter day as input, then it asks how much money you have, if day and money is suitable for
deal then algorithm suggest it otherwise says “sorry you can not have any deal in this range,
you can buy single item”. They showed following menu that bears information:

Designed By : Hira Farman


Day Customer Range (Rs) Menu Details
Monday

Deal 01, Deal 02, Deal 03 + complementary


101.00 and more
sweets
Tuesday
&
Wednesda Deal 01, Deal 04, Deal 05 + complementary
101.00 and more
y shake
Thursday
&
Friday 101.00 and more Deal 01, Deal 06, Deal 07 + complementary Falooda
Weekend 15.00 − 50.00 Deal 01 + complementary soup
s 150 / person Buffet
Table 4.2: Menu scheme of Bundoo Khan
2-AWSOMENESS

14. Perform the given operations using File handling concept of python
I. Write a Python program to create a file where all letters of English alphabet are liste by
specified number of letters on each line
II. Write a Python program to count the frequency of words in a file.
III. Write a Python program to append text to a file and display the text

15. Perform the given operation using Lambda function


I. program to count the even, odd numbers in a given array of integers using Lambda. 
II. program to add two given lists using map and lambda
III. program to a calculate area area of rectangle and triangle
IV. Python program to find palindromes in a given list of strings using Lambda

16. Write a Python program to perform following file operations


I. Write three employee’s information such as ID, Name, position and salary in a file.
II. read first n lines of a file
III. append 4 th employee’s information to existing file
IV. count the number of lines

17. Random Lottery Pick. Generate 100 random lottery tickets and pick two lucky tickets from it as a
winner.
Note you must adhere to the following conditions:
The lottery number must be 10 digits long.
All 100 ticket number must be unique.
Hint: Generate a random list of 1000 numbers using random.randrange()  and then
use random.sample() method to pick lucky 2 tickets.

18. Write a Python script to display the various Date Time formats – used python module date
a) Current date and time

Designed By : Hira Farman


b) Current year
c) Month of year
d) Week number of the year
e) Weekday of the week
f) Day of year
g) Day of the month
h) Day of week
19.Generate the given patterns using python language (Nesting of loop concept)

20. : Roll dice in such a way that every time you get the same numberDice has 6 numbers (from 1 to 6). Roll
dice in such a way that every time you must get the same output number. do this 5 times.

Reference article for help:

How to seed random number generator


random.choice()

There’s a way to amuse yourself while doing things and thats how I
look at efficiency. — Donald Knuth

Designed By : Hira Farman

You might also like