Programming Techniques Using Python
Programming Techniques Using Python
Ltd.
GRADE
STUDENT NAME:
PROGRAMME : DICT
ASSIGNMENT NO : 01
Task 1
UNDERLINE OR HIGHLIGHT THE CORRECT ANSWER
(15 Marks)
Question 1:
What is a correct syntax to output "Hello World" in Python?
I. echo("Hello World");
II. print("Hello World")
III. echo "Hello World"
IV. p("Hello World")
Question 2:
How do you insert COMMENTS in Python code?
I. #This is a comment
II. //This is a comment
III. /*This is a comment*/
IV. <! This is a comment >
Question 3:
Which one is NOT a legal variable name?
I. my-var
II. my_var
III. Myvar
IV. _myvar
1
Question 4:
How do you create a variable with the numeric value 5?
I. x = int(5)
II. x = 5
III. Both the other answers are correct
Question 5:
What is the correct file extension for Python files?
I. .py
II. .pt
III. .pyth
IV. .pyt
Question 6:
What is the correct syntax to output the type of a variable or object in Python?
I. print(type(x))
II. print(typeof x)
III. print(typeof(x))
IV. print(typeOf(x))
Question 7:
In Python, 'Hello', is the same as "Hello"
I. True
II. False
1
Question 8:
Which operator is used to multiply numbers?
I. *
II. x
III. #
IV. %
Question 9:
Which operator can be used to compare two values?
I. ==
II. <>
III. =
IV. ><
Question 10:
Which of these collections defines a LIST?
I. ["apple", "banana", "cherry"]
II. {"name": "apple", "color": "green"}
III. ("apple", "banana", "cherry")
IV. {"apple", "banana", "cherry"}
Question 11:
Which of these collections defines a TUPLE?
I. ("apple", "banana", "cherry")
II. ["apple", "banana", "cherry"]
III. {"name": "apple", "color": "green"}
IV. {"apple", "banana", "cherry"}
1
Question 12:
Which of these collections defines a SET?
I. {"apple", "banana", "cherry"}
II. ("apple", "banana", "cherry")
III. ["apple", "banana", "cherry"]
IV. {"name": "apple", "color": "green"}
Question 13:
Which of these collections defines a DICTIONARY?
I. {"name": "apple", "color": "green"} Your answer
II. ("apple", "banana", "cherry")
III. {"apple", "banana", "cherry"}
IV. ["apple", "banana", "cherry"]
Question 14:
How do you start writing an if statement in Python?
I. if x > y:
II. if (x > y)
III. if x > y then:
Question 15:
What is the correct way to create a function in Python?
I. def myFunction():
II. function myfunction():
III. create myFunction():
1
Task 2.
Write pseudo code that performs the following: Ask a user to enter a number. If the
number is between 0 and 10, write the word unicorn. If the number is between 10 and
20, write the word Phoenix. If the number is between 20 and 30, write the word
Pegasus. If it is any other number, write that it is Mermaid.
(10 marks)
Task 2.
1
Task 3.
Draw a flow chart for a program to input any number and display whether it is a positive
number or negative number. (10 marks)
1
Task 4
The flowchart inputs the size of a number of ship engine motors; a value of –3
stops the input. This information is the output: average Motor size and number
of Motors with size > 1.5
(10 marks)
1.8 2.0 1.0 1.3 1.0 2.5 2.0 1.3 1.8 1.3 -3
3
Motor Count Number Size Average OUTPUT
3
Task 5.
Draw a flow chart for a program to print 10 numbers from 10 to 100.
(10 marks)
3
DICT Assignment – Programming Techniques using Python
Part 2 –Python Programming
Task 6.
Write a program that asks the user for their name and greets them with their
name. (5 marks)
Task 7.
Write a program in python to input the number of years. Output the bonus
obtained according to the following criterion.
If number of years greater than 5
bonus -> 75000
If number of years between 5 to 4
bonus -> 50000
If number of years between 4 to 3
bonus -> 30000
If number of years between 3 to 2
bonus -> 20000
If number of years less than 1
bonus -> 10000
(10 marks)
Task 8.
Write a program in python to display as following , when assigning a number
to “a” and another number to “b”
b is greater than a
a and b are equal
a is greater than b
(10 marks)
1
1
Task 9
Write a program in Python to print each Subject in the list. You can assign any
three subjects and print each.
(10 marks)
Task 10.
Write a program in Python to input any number and display whether it is a
positive number or negative number.
1
2