Software Development Exam  >  Software Development Notes  >  Basics of Python  >  Assignment: Python Variables & Data Types

Assignment: Python Variables & Data Types | Basics of Python - Software Development PDF Download

Multiple Choice Questions (MCQs)

Q.1. Which of the following is not a valid variable name in Python?
(a) myVariable
(b) 123Variable
(c) _variable
(d) variable_123

Ans. (b)

Q.2. What is the correct way to declare and initialize a variable in Python?
(a) x = 5
(b) x := 5
(c) 5 = x
(d) x == 5

Ans. (a)

Q.3. Which of the following data types is immutable in Python?
(a) list
(b) dictionary
(c) tuple
(d) set

Ans. (c)

Q.4. What is the output of the following code snippet?
x = 5
y = "Hello"
print(x + y)

(a) 5Hello
(b) TypeError: unsupported operand type(s) for +: 'int' and 'str'
(c) HelloHelloHelloHelloHello
(d) Hello5

Ans. (b)

Q.5. Which operator is used for exponentiation in Python?
(a) +
(b) -
(c) *
(d) **

Ans. (d)

High Order Thinking Questions (HOTS)

Q.1. Write a Python program to swap the values of two variables without using a temporary variable.

x = 5

y = 10

x, y = y, x

print("x =", x)

print("y =", y)

Q.2. Write a Python program to calculate the area of a circle given the radius (Hint: Use the math module).

import math

radius = float(input("Enter the radius: "))

area = math.pi * radius ** 2

print("Area of the circle:", area)

Q.3. Write a Python program to check if a given year is a leap year or not.

year = int(input("Enter a year: "))

if (year % 4 == 0 and year % 100 != 0) or year % 400 == 0:

    print(year, "is a leap year")

else:

    print(year, "is not a leap year")

Q.4. Write a Python program to calculate the sum of the digits of a positive integer.

num = int(input("Enter a positive integer: "))

digit_sum = 0

while num > 0:

    digit_sum += num % 10

    num //= 10

print("Sum of digits:", digit_sum)

Q.5. Write a Python program to reverse a given list.

original_list = [1, 2, 3, 4, 5]

reversed_list = original_list[::-1]

print("Reversed list:", reversed_list)

Fill in the Blanks

Q.1. The process of assigning a value to a variable is called ________.

Ans. assignment

Q.2. In Python, the ________ function is used to convert a value to an integer.

Ans. int()

Q.3. A ________ is an ordered collection of elements, enclosed in square brackets [ ].

Ans. list

Q.4. The ________ operator returns the remainder when one number is divided by another.

Ans. % (modulo)

Q.5. The ________ statement is used to receive input from the user.

Ans. input

True or False


Q.1. In Python, variables do not need to be declared before using them.

Ans. True

Q.2. The data type of a variable in Python can be changed during the execution of the program.

Ans. True

Q.3. Python supports complex numbers as a built-in data type.

Ans. True

Q.4. The expression "5" + 3 will result in a TypeError.

Ans. True

Q.5. The len() function can be used to determine the number of elements in a list.

Ans. True

Hands-On Questions

Q.1. Write a Python program to calculate the area of a rectangle. Prompt the user to enter the length and width.

length = float(input("Enter the length: "))

width = float(input("Enter the width: "))

area = length * width

print("Area of the rectangle:", area)

Q.2. Write a Python program to convert a temperature in Celsius to Fahrenheit. Prompt the user to enter the temperature in Celsius.

celsius = float(input("Enter the temperature in Celsius: "))

fahrenheit = (celsius * 9/5) + 32

print("Temperature in Fahrenheit:", fahrenheit)

Q.3. Write a Python program to swap the values of two variables using a temporary variable.

x = 5

y = 10

temp = x

x = y

y = temp

print("x =", x)

print("y =", y)

Q.4. Write a Python program to check if a given string is a palindrome or not.

string = input("Enter a string: ")

reversed_string = string[::-1]

if string == reversed_string:

    print("Palindrome")

else:

    print("Not a palindrome")

Q.5. Write a Python program to find the largest element in a given list.

numbers = [5, 2, 9, 1, 7]

largest = max(numbers)

print("Largest element:", largest)

The document Assignment: Python Variables & Data Types | Basics of Python - Software Development is a part of the Software Development Course Basics of Python.
All you need of Software Development at this link: Software Development
49 videos|38 docs|18 tests

Top Courses for Software Development

49 videos|38 docs|18 tests
Download as PDF
Explore Courses for Software Development exam

Top Courses for Software Development

Signup for Free!
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev
Related Searches

past year papers

,

ppt

,

study material

,

Semester Notes

,

Exam

,

Summary

,

Assignment: Python Variables & Data Types | Basics of Python - Software Development

,

Viva Questions

,

MCQs

,

Assignment: Python Variables & Data Types | Basics of Python - Software Development

,

Sample Paper

,

video lectures

,

Extra Questions

,

Free

,

Previous Year Questions with Solutions

,

practice quizzes

,

pdf

,

shortcuts and tricks

,

Objective type Questions

,

Assignment: Python Variables & Data Types | Basics of Python - Software Development

,

Important questions

,

mock tests for examination

;