[PDF] python projects pdf
[PDF] python questions and answers
[PDF] python random number generator between 0 and 1
[PDF] python random number generator between range
[PDF] python random number generator example
[PDF] python random number generator normal distribution
[PDF] python random number generator numpy
[PDF] python random number generator stack overflow
[PDF] python random number generator without repeats
[PDF] python regular expression interview questions and answers
[PDF] python scipy hierarchical clustering example
[PDF] python scripting for arcgis ebook download
[PDF] python scripting for arcgis exercises
[PDF] python scripting for arcgis pro
[PDF] python scripting for arcgis pro book
Think Twice
Code Once
The Islamic University of Gaza
Engineering Faculty
Department of Computer Engineering
Fall 2017
LNGG 1003
Khaleel I. Shaheen
Introduction to Computers
Laboratory Manual
Final Exam Solution
1 The Islamic University of Gaza Student Name: _____________________ Engineering Faculty Student ID: ________________________ Department of Computer Engineering Time: 1 hour 30 minutes
Introduction to Computers LNGG 1003
Khaleel I. Shaheen Fall 2017
Final Exam
Part I) Theoretical Questions.
Question 1) Choose the correct answer:
1. Computer can execute the code in ____________.
machine language assembly language python language high-level language
2. Python syntax is case-sensitive
True False
3. A Python line comment begins with ________.
4. A Python paragraph comment uses the style ________.
// comments // /* comments */ /# comments #/ ''' comments '''
5. Which of the following code is correct?
print("Programming is fun") print("Python is fun") print("Programming is fun") print("Python is fun") print("Programming is fun) print("Python is fun") print("Programming is fun) print("Python is fun")
6. An identifier can be a keyword?
True False
7. Which of the following is a valid identifier?
$343 mile 9X 8+9
8. Which of the following is a valid identifier? (choose multiple)
While Kilo1 Mile (red)
2
9. What will be displayed by the following code?
x = 1 x = 2 * x + 1 print(x)
1 2 3 4
10. What will be displayed by the following code?
x, y = 1, 2 x, y = y, x print(y, x)
1 1 2 2 2 1 1 2
11. What is the result of 45 / 4?
10 11 11.25 12
12. Which of the following expression results in a value 1?
2 % 1 15 % 4 25 % 5 37 % 6
13. What is 2 ** 3 evaluates to __________.
8 9 8.0 9.0
14. What is x after the following statements?
x = 1 x *= x + 1
1 2 3 4
15. Analyze the following code:
even = False if even: print("It is even!")
The code displays It
is even!
The code displays
nothing.
The code is wrong.
replace if even: with if even == True:
The code is wrong.
replace if even: with if even = True: 3
16. The following code displays ___________.
temperature = 50 if temperature >= 100: print("too hot") elif temperature <= 40: print("too cold") else: print("just right") too hot too cold just right too hot too cold just right
17. What is y after the following statement is executed?
x = 0 y = 10 if x > 0 else -10 -10 0 10 wrong expression
18. What is the value of the following expression?
print(True or True and False)
True False
19. Which of the following operators is right-associative.
+ * and =
20. How many times will the following code print "Welcome to Python"?
count = 0 while count < 10: print("Welcome to Python")
9 10 11 infinite number of times
21. What will be displayed when the following code is executed?
number = 6 while number > 0: number -= 3 print(number)
6 3 0 6 3 3 0 3 0 -3
22. The function range(5) return a sequence ______________.
1, 2, 3, 4, 5 0, 1, 2, 3, 4, 5 1, 2, 3, 4 0, 1, 2, 3, 4
23. Which of the following function is incorrect? (choose multiple)
range(0, 3.5) range(10, 4, -1) range(1, 3, 1) range(2.5, 4.5) 4
24. Will the following program terminate?
balance = 10 while True: if balance < 9: break balance = balance - 9
Yes No
25. Will the following program terminate?
balance = 10 while True: if balance < 9: continue balance = balance - 9
Yes No
26. A function _________.
must have at least one parameter may have no parameters must always have a return statement to return a value must always have a return statement to return multiple values
27. Given the following function
def nPrint(message, n): while n > 0: print(message) n -= 1 What will be displayed by the call nPrint('a', 4)? aaaa aaa invalid call infinite loop
28. What will be displayed by the following code?
def f1(x=1, y=2): x = x + y y += 1 print(x, y) f1()
1 3 3 1 1 1 3 3
29. Which of the following functions return 4.0
int(3.4) int(3.9) eval(3.4) round(3.5)
30. how difficult is the exam? (all answers are correct).
Very Easy ૃ Easy Medium Difficult Very Difficult ͓ 5 Part II) Practical Questions: Solve the following questions. print((9.5 * 4.5 - 2.5 * 3) / (45.5 - 3.5)) Question 3) Write a program that prompts the user to enter the side of a hexagon and displays its area. The formula for computing the area of a hexagon is ܣൌଷכ of a side. side = input("Enter the side: ") area = (3 * 3 ** 0.5 * side ** 2) / 2 print("The area of the hexagon is " + str(area)) Question 4) Write a Python program that uses an if statement to find the smallest of three given integers. (The user should enter the three numbers). num1 = input("Enter num1: ") num2 = input("Enter num2: ") num3 = input("Enter num3: ") if num1 < num2 and num1 < num3: min = num1 elif num2 < num1 and num2 < num3: min = num2 else: min = num3 print("Smallest is", min) Question 5) Write a function that take two numbers, x and y, and returns the sum of numbers from x to y. def sum_range(x, y): sum = 0 for i in range(x, y + 1): sum += i return sum 6 Question 6) Write factorial(num) function that returns the factorial of an integer. Write a test program to call factorial function with input entered by user. def factorial(num): fact = 1 for i in range(1, num + 1): fact *= i return fact n = input("Eter number: ") print(factorial(n))
All the Best,
quotesdbs_dbs19.pdfusesText_25