Professional Documents
Culture Documents
a. 6
b. 24
c. 6.0
d. 42
8. What is the output of this code?
spam = "7"
spam = spam + "0"
eggs = int(spam) + 3
print(float(eggs)).
a. 73.0
b. 73
c. 10.0
d. 703
9. What is the output of this code if the user enter '42' as input:
age = int(input())
print(age+8)
a. 428
b. 50
c. 50.0
d. invalid syntax
10. What are the two Boolean values in Python.
a. true and false
b. Truth and Falsity
c. True and False
d. truth and falsity
11. Comparison operators are also called.........
a. Relational operators
Page 1 of 14
Misr University for Science and Technology
Information Technology College
b. Assignment operators
c. arithmetic operators
d. Logical operators
12.
a. eight
b. five
c. five eight
d. nothing
13.
15.
a. Line 2
b. Line 3
c. Line 4
d. Line 1
21. What happens if you open a file in write mode and then immediately close it?
a. A blank line is written to the file
b. Nothing changes
c. The file contents are deleted
d. The file is deleted
Page 2 of 14
Misr University for Science and Technology
Information Technology College
:Question 2
:Choose True or False (True is the left bubble, False is right bubble before each question on the sheet)
5. you can assign a string to a variable, and later assign an integer to the same variable.
6. taking the age of the user as input:
age =(input())
print(age)
import sys
print (sys.version)
Page 3 of 14
Misr University for Science and Technology
Information Technology College
import datetime
)(now = datetime.datetime.now
Page 4 of 14
Misr University for Science and Technology
Information Technology College
exam_st_date = (11,12,2014)
print( "The examination will start from : %i / %i /
%i"%exam_st_date)
Page 5 of 14
Misr University for Science and Technology
Information Technology College
print("""
a string that you "don't" have to escape
This
is a ....... multi-line
heredoc string --------> example
""")
def difference(n):
if n <= 17:
return 17 - n
else:
return (n - 17) * 2
print(difference(22))
print(difference(14))
def near_thousand(n):
return ((abs(1000 - n) <= 100) or (abs(2000 - n) <= 100))
print(near_thousand(1000))
print(near_thousand(900))
Page 6 of 14
Misr University for Science and Technology
Information Technology College
print(near_thousand(800))
print(near_thousand(2200))
sum = x + y + z
if x == y == z:
sum = sum * 3
return sum
print(sum_thrice(1, 2, 3))
print(sum_thrice(3, 3, 3))
def new_string(str):
if len(str) >= 2 and str[:2] == "Is":
return str
return "Is" + str
print(new_string("Array"))
print(new_string("IsEmpty"))
def new_string(str):
if len(str) >= 2 and str[:2] == "Is":
return str
return "Is" + str
print(new_string("Array"))
print(new_string("IsEmpty"))
Page 7 of 14
Misr University for Science and Technology
Information Technology College
def list_count_4(nums):
count = 0
for num in nums:
if num == 4:
count = count + 1
return count
print(list_count_4([1, 4, 6, 7, 4]))
print(list_count_4([1, 4, 6, 4, 7, 4]))
result = ""
for i in range(n):
result = result + substr
return result
print(substring_copy('abcdef', 2))
Page 8 of 14
Misr University for Science and Technology
Information Technology College
print(substring_copy('p', 3));
def is_vowel(char):
all_vowels = 'aeiou'
return char in all_vowels
print(is_vowel('c'))
print(is_vowel('e'))
if n == value:
return True
return False
Contents of text.txt
……..
……..
……….
Python Code:
def file_read(fname):
Page 9 of 14
Misr University for Science and Technology
Information Technology College
txt = open(fname)
print(txt.read())
file_read('test.txt')
Example:
def tips_digit(n):
return list(map(int, str(n)))
print(tips_digit(2468))
Output:
[2, 4, 6, 8]
31. Write a Python program to read a file line by line and store
it into a list.
Page 10 of 14
Misr University for Science and Technology
Information Technology College
37. Write a Python program to get the file size of a plain file.
40. Write a Python program to combine each line from first file
with the corresponding line in second file.
r = lambda a : a + 15
print(r(10))
r = lambda x, y : x * y
print(r(12, 4))
Page 11 of 14
Misr University for Science and Technology
Information Technology College
print(subject_marks)
print(subject_marks)
Page 12 of 14
Misr University for Science and Technology
Information Technology College
49. Write a Python program that accepts a word from the user
and reverse it.
51. Write a Python program that prints each item and its
corresponding type from the following list.
Sample List : datalist = [1452, 11.23, 1+2j, True, 'w3resource',
(0, -1), [5, 12], {"class":'V', "section":'A'}]
52. Write a Python program that prints all the numbers from 0
to 6 except 3 and 6.
Note : Use 'continue' statement.
Expected Output : 0 1 2 4 5
fizz
4
buzz
55. Write a Python program which takes two digits m (row) and
n (column) as input and generates a two-dimensional array.
The element value in the i-th row and j-th column of the array
should be i*j.
Page 14 of 14