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

CSCI101_Lab07_Algorithms I

The document outlines a series of programming exercises for an Introduction to Computer Science course, focusing on algorithms and basic coding concepts. It includes problems related to logical expressions, control flow, loops, and user input handling. Additionally, it presents practical tasks such as creating a multiplication table, sorting grades and student names, and managing a grocery store's delivery service.

Uploaded by

fatemamansour01
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views

CSCI101_Lab07_Algorithms I

The document outlines a series of programming exercises for an Introduction to Computer Science course, focusing on algorithms and basic coding concepts. It includes problems related to logical expressions, control flow, loops, and user input handling. Additionally, it presents practical tasks such as creating a multiplication table, sorting grades and student names, and managing a grocery store's delivery service.

Uploaded by

fatemamansour01
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

University of Science and Technology

Communications & Information Engineering Program


CSCI 101: Introduction to Computer Science
Algorithms I

Note: Problems 1-8 should be solved on paper then checked on computer


1. If A is false and B is true, then which of the following expressions is false?
o not A and A or A Clearly circle ALL correct answers.
o not A or A and A
o A or not A or B
o not (A and B or A)

2. The expression (math.trunc(1.5) + 15%3 ) < 2 is


o Invalid Clearly circle only one answer.
o True
o False

3. What is the output of the following code?


Q=5; R=10; T=2
if (Q>T or Q>8) and (T<=4):
R=R/10

if (T==0 or Q==2 or R<T) and (T>-5):


R=4
print(R)

4. For each part below, what is the value of C after the code executes,
(a) (b)
B = 60; C=15 B = 60; C=15
if B >= 20: if B >= 20:
C=9 C=9
elif C < 10: if C < 10:
C=11 C=11

Page 1
University of Science and Technology
Communications & Information Engineering Program
CSCI 101: Introduction to Computer Science
Algorithms I

5. Which command is usually used to repeat a set of commands an unknown number


of times?
o while Clearly circle only one answer.
o for
o if

6. Which of the following for statements will run 10 times :


o for 1:10: Clearly circle all correct answers.
o for i in range(21,31):
o for i in range(1,10):
o for i in range(1,11,1):
o for i in range(1,11,0):
o for i in range(11,1,-1):

7. which of the following loops will run forever :


o while 1: Clearly circle all correct answers.
o while -3:
o while 0:
o while True:
o while False:
o for i in ‘orange’:
o x = [1] #Interesting once, try it on the computer
for i in x:
print(x)
x.append(1)

Page 2
University of Science and Technology
Communications & Information Engineering Program
CSCI 101: Introduction to Computer Science
Algorithms I

8. What is the output of the following pieces of code:


x = 10; y=15; z = 3; h = False; m= True
if ( y>z or m and not (h and m) and y>z or (z>1 and y>10) ) and x>y :
print(‘oh No! long condition !!’)
else:
print(‘YES, got it’)
9. Write a program that reads a number N from the user and prints the following
multiplication table:
1
2 4
3 6 9
4 8 12 16
5 10 15 20 25

10. [without using function sort]


CS course has two sections, you need to take grades and students’ lists from the doctor
and sort them in descending order
a) print the two grades sorted lists
b) print the two students sorted lists
c) print the student with the highest grade and his/her class

Example:
class 1 grades: 4 1 2 421
class 1 students: ahmed mohamed yasser
class 2 grades: 7 10 8
class 2 students: samaa ehab roaa

Page 3
University of Science and Technology
Communications & Information Engineering Program
CSCI 101: Introduction to Computer Science
Algorithms I

class 1 grades sorted from highest to lowest grade [4, 2, 1]


class 2 grades sorted from highest to lowest grade [10, 8, 7]
class 1 students sorted from highest to lowest grade [‘ahmed’, 'yasser', 'mohamed']
class 2 students sorted from highest to lowest grade ['ehab', 'roaa', 'samaa']
The student with the highest grade is ehab in class 2
11. Take N from user and print based on it the following shape:
*
*
*
*
*
*
*
*
*
*
# This is an example when N = 5. You should solve for any N.

12. A grocery store launched its delivery service from 8 AM to 9 PM. Number of items
changes everyday and is updated by the stock clerks.

Main departments are:

Meat - Seafood - Milk - Bread - Oil

a) Take from the stock clerk the available number in each department and the new
prices.
b) You can take orders from customers till the end of all items or end of working
hours and print for each the total they should pay.

Page 4
University of Science and Technology
Communications & Information Engineering Program
CSCI 101: Introduction to Computer Science
Algorithms I

c) make a promo code with 30% discount ‘123456’ as anyone tells it takes this
discount but only on Milk
d) make a report for the grocery manager showing ratios of sold products from
each department to know what they should buy more next time.
ratio = (number of sold items from a department)/total number of sold items
e) print the ratios in the report in an ascending order.

Example:

how many available items in the following departments?


Meat - Seafood - Milk - Bread - Oil>? 2 2 2 2 2
what are the prices of the available items in the following departments?
Meat - Seafood - Milk - Bread - Oil>? 1 2 3 4 5
how many you want from each of the following:
Meat - Seafood - Milk - Bread - Oil>? 1 0 1 1 2
please enter promo if you have: >? 123456
Dear prospective customer, the total is: 17.1 pounds
is the store still open? >? yes
how many you want from each of the following:
Meat - Seafood - Milk - Bread - Oil>? 1 1 1 1 1
please enter promo if you have: >?
we are sorry there's no available Oil
Dear prospective customer, the total is: 10.0 pounds
is the store still open? >? yes
how many you want from each of the following:
Meat - Seafood - Milk - Bread - Oil>? 0 2 0 0 0
please enter promo if you have: >?
there are only 1 available of Seafood we put it in your cart
Dear prospective customer, the total is: 2.0 pounds
is the store still open? >? no

Page 5
University of Science and Technology
Communications & Information Engineering Program
CSCI 101: Introduction to Computer Science
Algorithms I

We sold today:
20.00 % Meat
20.00 % Seafood
20.00 % Milk
20.00 % Bread
20.00 % Oil

Page 6

You might also like