0% found this document useful (0 votes)
43 views4 pages

Revision 2 Prog2

The document contains code for creating a simple GUI with Tkinter and a line plot with Matplotlib. It then provides multiple choice questions to test the understanding of the code. The questions cover topics like Tkinter widgets, handling button click events, Matplotlib plotting, and data preprocessing with Pandas.

Uploaded by

Rawan Tamer
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)
43 views4 pages

Revision 2 Prog2

The document contains code for creating a simple GUI with Tkinter and a line plot with Matplotlib. It then provides multiple choice questions to test the understanding of the code. The questions cover topics like Tkinter widgets, handling button click events, Matplotlib plotting, and data preprocessing with Pandas.

Uploaded by

Rawan Tamer
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
You are on page 1/ 4

Final Revision Sheet

Part One: GUI


1. import tkinter as tk
2. def on_button_click():
3. label.config(text="Button clicked!")
4. root = tk.Tk()
5. root.title("Simple GUI")
6. label = tk.Label(root, text="Hello, GUI!")
7. label.pack()
8. button = tk.Button(root, text="Click Me",
command=on_button_click)
9. button.pack()
10. root.mainloop()

According to the previous code, answer the following questions from 1 to 8

1. What will be displayed on the GUI window when the button is clicked?
a) "Hello, GUI!"
b) "Button clicked!"
c) Nothing will change.
d) An error will occur.
Answer: b) "Button clicked!"
2. Which Tkinter widget is used to display a text label?
a) Label
b) Entry
c) Button
d) Canvas
Answer: a) Label.
3. What will happen if the line number 5: root.title("Simple GUI") is removed from the code?
a) The GUI window will not have a title.
b) An error will occur when running the code.
c) The label text will not be displayed on the GUI window.
d) The button click event will not be handled.
Answer: a) The GUI window will not have a title.
4. What will happen if the line number 9: button. pack () is moved above label.pack()?
a) The button will be displayed above the label on the GUI window.
b) The label text will not be displayed on the GUI window.
c) The button click event will not be handled.
d) An error will occur when running the code.
Answer: a) The button will be displayed above the label on the GUI window.
5. What will happen if line 8: command=on_button_click is changed to command=on_button_click ()?
a) The button click event will not be handled.
b) An error will occur when running the code.
c) The label text will not be displayed on the GUI window.
d) The button will not be displayed on the GUI window.
Answer: b) An error will occur when running the code.

6. What will happen if line3: label.config (text="Button clicked!") is changed to button.config


(text="Button clicked!")?
a) The label text will be changed to "Button clicked!".
b) The button text will be changed to "Button clicked!".
c) The button click event will not be handled.
d) An error will occur when running the code.
Answer: d) An error will occur when running the code.
7-Which widget are used to get the data from the user ?
A) Entry B) Label C) Button D) None of the above
8- fg in tkinter widget is stands for ?
(a) foreground
(b) background
(c) forgap
(d) None of the above

Part Two: Data visualization

1. import matplotlib.pyplot as plt


2. x = [1, 2, 3, 4, 5]
3. y = [10, 20, 15, 25, 30]
4. plt.plot(x, y)
5. plt.xlabel('X-axis')
6. plt.ylabel('Y-axis')
7. plt.title('Line Plot')
8. plt.show()

According to the previous code, answer the following question from 1 to 3

1. What type of plot is being created by the given code?

a) Scatter plot
b) Line plot
c) Bar plot
d) Histogram
Answer: b) Line plot
2. Which Python library is commonly used for creating data visualizations?
a) NumPy
b) Pandas
c) Matplotlib
d) Scikit-learn
Answer: c) Matplotlib
3-Which of the following methods should be employed in the code to print the created plot?

a-show() b-display() c-execute() d-plot()

Part three : data preprocessing


1-Which method is used to detect missing values in a DataFrame in pandas?

a) find_missing()
b) detect_nulls()
c) is_null()
d) isna()
Answer: d) isna()
2-The following code create a dataframe named ‘D1’ with _______________ columns. import
pandas as pd D1 = pd.DataFrame([1,2,3] ) a-1 b-2 c-3 d-4

3-Which function is used to discover duplicates? A- repeatead() b- replicated() c- duplicated() d- none

Part 4 : OOP
1-Which of the following is correct with respect to OOP concept in Python?

A. Objects are real world entities while classes are not real.
B. Classes are real world entities while objects are not real.
C. Both objects and classes are real world entities.
D. Both object and classes are not real.
2-
Which of the following is an example of polymorphism in Python?
a) Using the + operator to concatenate two strings
b) Accessing different elements in a list using indexing
c) Defining a class with multiple methods having the same name but different parameters
d) Storing different data types in a single list
Answer: c) Defining a class with multiple methods having the same name but different parameters

Polymorphism is closely related to which principle of object-oriented programming?


a) Inheritance
b) Encapsulation
c) Abstraction
d) Composition
Answer: a) Inheritance

You might also like