0% found this document useful (0 votes)
5 views7 pages

Python Variable Declaration Guide

The document provides a series of questions and tasks related to declaring variables, data types, and basic programming concepts in Python. It includes multiple-choice questions about variable naming conventions, legal variable names, and syntax for printing and converting data types. Additionally, it contains programming exercises for user input and conditional statements to determine grades and eligibility based on various criteria.

Uploaded by

yucheung man
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views7 pages

Python Variable Declaration Guide

The document provides a series of questions and tasks related to declaring variables, data types, and basic programming concepts in Python. It includes multiple-choice questions about variable naming conventions, legal variable names, and syntax for printing and converting data types. Additionally, it contains programming exercises for user input and conditional statements to determine grades and eligibility based on various criteria.

Uploaded by

yucheung man
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

What is the correct way to declare a Python variable?

A. Var x = 5
B. #x = 5
C. $x = 5
D. x = 5

You can declare string variables with single or double quotes.

x = "John"

# is the same as

x = 'John'

A. True
B. False

Variable names are not case-sensitive.

a=5

# is the same as

A=5

A. True
B. False

Which is NOT a legal variable name?

A. my-var = 20
B. my_var = 20
C. Myvar = 20
D. _myvar = 20

Create a variable named carname and assign the value Volvo to it.
_________________________ = __________________________

Create a variable named x and assign the value 50 to it.

__________ = __________

The following code example would print the data type of x, what data type would that
be?

x=5

print(type(x))

_________

The following code example would print the data type of x, what data type would that
be?

x = "Hello World"

print(type(x))

___________

The following code example would print the data type of x, what data type would that
be?

x = 20.5

print(type(x))

__________

Which is NOT a legal numeric data type in Python:


A. int
B. long
C. float

Insert the correct syntax to convert x into a floating-point number.

x=5

x = ______(x)

What is a correct syntax to output "Hello World" in Python?

A. print (“Hello World”)


B. p “(Hello World)”
C. Print (‘Hello World’)
D. P (Hello World)

Which one is NOT a legal variable name?

A. _Maryisfat
B. 2005-Mary__
C. Mary_is_fat
D. Mary_2005

How do you create a variable with the numeric value 5?

A. x = int(5)
B. x = float(5)
C. x = “5”
D. all of the above

Write a program to check whether a person is eligible to vote or not. (accept age from
user)
Write a program to check whether a number entered by the user is odd or even.

Write a program to display “Hello” if a number entered by the user is a multiple of


five. Otherwise, print “Bye”.
Q1. Write a program to accept percentage from the user and display the grade
according to the following criteria:

Marks > 90

Grade A

> 80 and <= 90

>= 60 and <= 80

below 60

D
Q2. Accept the following from the user and calculate the percentage of class attended:

a. Total number of working days

b. Total number of days for absence

After calculating the percentage, it shows that if the percentage is less than 75, then
the student will not be able to sit in the exam.
Q3. Accept the percentage from the user and display the grade according to the
following criteria:

Below 25 D

25 to 45 C

45 to 50 B

50 to 60 B+

60 to 80 A

Above 80 A+

You might also like