0% found this document useful (0 votes)
28 views2 pages

Python Question Bank for B.Tech Students

The document is a Python question bank designed for first-year B.Tech students, containing various programming exercises categorized into Python Basics, If-Else-Elif, For Loop, and Mixed Logic questions. Each category includes multiple tasks aimed at enhancing students' understanding and application of Python programming concepts. The questions range from simple output tasks to more complex logic and mathematical operations.
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)
28 views2 pages

Python Question Bank for B.Tech Students

The document is a Python question bank designed for first-year B.Tech students, containing various programming exercises categorized into Python Basics, If-Else-Elif, For Loop, and Mixed Logic questions. Each category includes multiple tasks aimed at enhancing students' understanding and application of Python programming concepts. The questions range from simple output tasks to more complex logic and mathematical operations.
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

Python Question Bank for First Year B.

Tech
Students

Python Basics Questions

1. Write a Python program to print 'Hello, World!'.


2. Write a program to take two numbers as input and print their sum, difference, product, and
quotient.
3. Write a program to swap two numbers without using a third variable.
4. Write a program to check whether a number is even or odd.
5. Write a program to find the largest among three numbers.

If-Else-Elif Questions

6. Write a program to check whether a number is positive, negative, or zero.


7. Write a program to check whether a given year is a leap year or not.
8. Write a program to input marks of a student and print the grade as per the following rules: -
90–100 → Grade A - 75–89 → Grade B - 50–74 → Grade C - Below 50 → Grade F
9. Write a program to check whether a character entered by the user is a vowel or consonant.
10. Write a program to find the greatest of four numbers using if-elif-else.

For Loop Questions

11. Write a program to print the first 10 natural numbers using a for loop.
12. Write a program to print the multiplication table of a given number.
13. Write a program to find the sum of numbers from 1 to n.
14. Write a program to print all even numbers between 1 and 100.
15. Write a program to print factorial of a number.
16. Write a program to print Fibonacci series up to n terms.
17. Write a program to count the number of digits in a number.
18. Write a program to reverse a number using loop.
19. Write a program to check whether a given number is prime or not.
20. Write a program to print all prime numbers between 1 and 100.

Mixed Logic Questions

21. Write a program to check whether a number is an Armstrong number.


22. Write a program to check whether a number is a palindrome.
23. Write a program to calculate the sum of digits of a number.
24. Write a program to find the smallest divisor of a number greater than 1.
25. Write a program to generate a pattern like: * * * * * * * * * *

Common questions

Powered by AI

To determine if a year is a leap year in Python, you can use the following rule: a year is a leap year if it is divisible by 4 but not divisible by 100, unless it is also divisible by 400. This is important in programming because leap years affect calendar calculations, which are integral to software that deals with dates . For example, in Python, you can implement this check using an if-else statement as follows: if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0): print('Leap Year') else: print('Not a Leap Year').

An Armstrong number is an integer where the sum of its digits raised to the power of the number of digits equals the number itself. This is interesting in digital mathematics because it represents self-contained mathematical properties that can be efficiently verified through algorithms. In Python, calculate this by iterating through each digit, raising it to the power of the total count of digits, then summing the results . If this sum equals the original number, it qualifies as an Armstrong number, useful for exercises in understanding control structures and power functions.

Counting the number of digits in a number is useful when validating input size, computational requirements in algorithms like dynamic programming, or formatting outputs. In Python, you can implement this using a loop that continuously divides the number by 10 until it becomes zero, incrementing a counter at each step to record the number of iterations . This ensures that the count reflects the correct number of digits. This implementation is straightforward, relying on simple arithmetic division and a while loop.

The Fibonacci series is significant as it demonstrates recursive phenomena and is prevalent in computer science and mathematics. In Python, printing Fibonacci series using loops avoids the overhead of recursive calls, which can lead to a stack overflow for large n. To implement using a loop, initialize the first two numbers and iterate to calculate the next numbers using the sum of the preceding two numbers . This method is efficient for larger terms of Fibonacci calculations compared to recursion because it has constant space complexity and linear time complexity.

To determine the greatest of four numbers in Python, you can use a series of if-elif statements to compare the numbers sequentially or make use of the built-in max() function for a cleaner approach. This approach is efficient because it minimizes the number of comparisons to n-1 for n numbers, thus optimizing performance with reduced computational complexity . Implementing with if-elif, you would compare each number in pairs or collectively determine the maximum using max(a, b, c, d).

Calculating the factorial of a number in Python is achieved using loops or recursion. The factorial function (n!) is a product of all positive integers up to n, useful in permutations, combinations, and other areas of mathematics. A loop-based calculation involves initializing a result variable to 1, iterating from 1 to n, multiplying the result at each step . Despite being simple, factorials are fundamental to combinatorial computations, and their iterative computation prevents recursion limit issues, ensuring better performance compared to recursive methods.

Swapping two numbers without using a third variable is often achieved using arithmetic operations or bitwise XOR operation. The logic involves adding both numbers and storing the result in one of them, then using subtraction to complete the swap without extra storage. This technique optimizes space usage, which is crucial in environments with limited memory . In Python, this can be done by x = x + y; y = x - y; x = x - y or using XOR: x = x ^ y; y = x ^ y; x = x ^ y.

To verify if a number is a palindrome in Python, check if it reads the same forwards and backwards. This can be achieved by converting the number to a string and comparing it with its reverse . Palindrome numbers are of practical use in computing, particularly in error detection schemes like check digit systems and within algorithms that require symmetry properties. They challenge programmers with creative verification problems and ensure understanding of string manipulation and symmetry.

Generating a multiplication table for a given number involves using a loop to iterate through a sequence of multiplier numbers. For each iteration, multiply the given number by the iterator and print the result . This simple yet practical exercise has applications in educational software for teaching multiplication concepts and practice. It helps reinforce looping structures and arithmetic calculations in programming while serving practical mathematical educational purposes.

Identifying prime numbers is significant in programming for cryptographic algorithms, random prime generation, and optimization tasks. In Python, a common strategy involves iterating from 2 to √n for each number, checking for divisibility to ensure efficiency . This method ensures the program can identify primes within a defined range without performing unnecessary operations, crucial in computational tasks where efficiency is important. The use of nested loops and conditional checks embodies a fundamental aspect of complexity handling in algorithms.

You might also like