ETP Questions

INT108

Q1. Coding Problem Easy
Topic: Expressions and Operators

Unit 1: Temperature Converter

Write a program that takes a temperature in Celsius as input (float) and converts it to Fahrenheit using the formula: .

Input Format:

TEXT
25.0

Output Format:

TEXT
77.0

Q2. Coding Problem Easy
Topic: Variables and Assignments

Unit 1: Variable Swapping

Write a program to swap two integer inputs without using a temporary variable (using Python's tuple assignment).

Input Format:

TEXT
10
20

Output Format:

TEXT
a: 20
b: 10

Q3. Coding Problem Medium
Topic: Modulus and Floor Division

Unit 1: Time Converter

Write a program that takes a total number of minutes as input and converts it into Hours and Minutes using floor division (//) and modulus (%).

Input Format:

TEXT
130

Output Format:

TEXT
2 Hours and 10 Minutes

Q4. Coding Problem Medium
Topic: String Operations

Unit 1: String Repetition and Concatenation

Write a program that takes a string word and a number n. Print the word repeated n times, followed by the string "!!!", all concatenated together.

Input Format:

TEXT
Go
3

Output Format:

TEXT
GoGoGo!!!

Q5. Coding Problem Easy
Topic: Conditional Statements

Unit 2: Leap Year Checker

Write a program that takes a year as input and checks if it is a leap year. A year is a leap year if it is divisible by 4, except for end-of-century years, which must be divisible by 400.

Input Format:

TEXT
2000

Output Format:

TEXT
Leap Year

Q6. Coding Problem Medium
Topic: While Loops

Unit 2: Sum of Digits

Write a program using a while loop to calculate the sum of digits of a given integer.

Input Format:

TEXT
12345

Output Format:

TEXT
15

Q7. Coding Problem Medium
Topic: For Loops and Range

Unit 2: Prime Number Checker

Write a program that checks if a given number n is a prime number using a for loop.

Input Format:

TEXT
7

Output Format:

TEXT
Prime

Q8. Coding Problem Easy
Topic: Random Numbers

Unit 2: Random Dice Simulation

Write a program that simulates rolling a 6-sided die. Import the random module and print a random integer between 1 and 6 (inclusive).

Input Format:

TEXT
(No input)

Output Format:

TEXT
(Any number between 1 and 6, e.g., 4)

Q9. Coding Problem Easy
Topic: Functions

Unit 3: Calculator Function

Define a function calculate(a, b, operator) that takes two numbers and a string operator ('+', '-', '*', '/') and returns the result. Handle division by zero by returning None.

Input Format:

TEXT
10
5
+

Output Format:

TEXT
15

Q10. Coding Problem Medium
Topic: Recursion

Unit 3: Recursive Factorial

Write a recursive function factorial(n) that calculates the factorial of a number.

Input Format:

TEXT
5

Output Format:

TEXT
120

Q11. Coding Problem Easy
Topic: Math Module

Unit 3: Hypotenuse Calculator

Write a function that uses math.sqrt and math.pow to calculate the length of the hypotenuse of a right triangle given sides a and b.

Input Format:

TEXT
3
4

Output Format:

TEXT
5.0

Q12. Coding Problem Medium
Topic: Arbitrary Arguments

Unit 3: Sum of Arbitrary Arguments

Write a function sum_all(*args) that takes any number of integer arguments and returns their sum.

Input Format:

TEXT
1 2 3 4 5

Output Format:

TEXT
15

Q13. Coding Problem Easy
Topic: Strings

Unit 4: Palindrome Check

Write a program that checks if a given string is a palindrome (reads the same forward and backward), ignoring case.

Input Format:

TEXT
Racecar

Output Format:

TEXT
True

Q14. Coding Problem Medium
Topic: Lists

Unit 4: Filter Even Numbers

Write a program that takes a list of integers and returns a new list containing only the even numbers, sorted in ascending order.

Input Format:

TEXT
9 2 5 4 8 1

Output Format:

TEXT
[2, 4, 8]

Q15. Coding Problem Medium
Topic: Dictionaries

Unit 4: Character Frequency

Write a program that counts the frequency of each character in a string and stores it in a dictionary.

Input Format:

TEXT
hello

Output Format:

TEXT
{'h': 1, 'e': 1, 'l': 2, 'o': 1}

Q16. Coding Problem Medium
Topic: Tuples

Unit 4: Tuple List Sort

Given a list of tuples where each tuple contains (name, age), write a program to sort the list by age (the second element).

Input Format (Hardcoded in solution for demo):

TEXT
[('Bob', 30), ('Alice', 25), ('Charlie', 35)]

Output Format:

TEXT
[('Alice', 25), ('Bob', 30), ('Charlie', 35)]

Q17. Coding Problem Easy
Topic: Classes and Objects

Unit 5: Rectangle Class

Create a class Rectangle with an __init__ method that accepts length and width. Add a method area() that returns the area.

Input Format:

TEXT
10
5

Output Format:

TEXT
50

Q18. Coding Problem Medium
Topic: Encapsulation

Unit 5: Bank Account

Create a class Account with a private attribute __balance. Add methods deposit(amount) and get_balance(). Ensure deposit is positive.

Input Format:

TEXT
1000
500

Output Format:

TEXT
1500

Q19. Coding Problem Medium
Topic: Inheritance

Unit 5: Animal Inheritance

Create a parent class Animal with a method speak() returning "Silence". Create a child class Dog that overrides speak() to return "Bark".

Input Format:

TEXT
(No input)

Output Format:

TEXT
Bark

Q20. Coding Problem Easy
Topic: Polymorphism/Methods

Unit 5: Student Class

Create a Student class initialized with name and grades (a list). Add a method average_grade().

Input Format:

TEXT
Alice
80 90 100

Output Format:

TEXT
90.0

Q21. Coding Problem Easy
Topic: Exception Handling

Unit 6: Safe Division

Write a program that takes two numbers as input and divides them. Use a try-except block to handle ZeroDivisionError and print "Cannot divide by zero".

Input Format:

TEXT
10
0

Output Format:

TEXT
Cannot divide by zero

Q22. Coding Problem Medium
Topic: Regex

Unit 6: Extract Numbers

Write a program using the re module to find all integers in a given string and print them as a list of strings.

Input Format:

TEXT
Order 45 items for $200

Output Format:

TEXT
['45', '200']

Q23. Coding Problem Hard
Topic: Regex

Unit 6: Email Validation

Write a function using Regex to validate if an input string is a basic valid email address (contains characters, an @ symbol, domain, dot, and extension).

Input Format:

TEXT
test@example.com

Output Format:

TEXT
Valid

Q24. Coding Problem Medium
Topic: File Handling (Simulation)

Unit 6: File Write Simulation

Write a code block that opens a file named 'output.txt' in write mode, writes "Hello World" to it, and ensures the file is closed automatically using a context manager.

Input Format:

TEXT
(No input)

Output Format:

TEXT
(File output.txt created with content "Hello World")