Python Programming Tasks


Basics - Variables

1. Write a Python program to print "Hello, World!"
2. Write a Python program to declare and initialize an integer, a float, and a character variable. Then print their values in a single line with proper formatting.
3. Write a Python program to swap the values of two integer variables using a temporary variable.
4. Write a Python program to find and display the memory size (in bytes) allocated to different data types: int, float, char, and double.
5. Write a Python program to take the name of a user as input and display it on the screen.

Operators

6. Write a Python program to demonstrate the use of arithmetic operators (+, -, *, /, %) on two integer numbers.
7. Write a Python program to demonstrate the use of relational operators (==, !=, >, <, >=, <=) between two numbers.
8. Write a Python program to demonstrate the use of logical operators (and, or, not) on two conditions.
9. Write a Python program to demonstrate the use of assignment operators (=, +=, -=, *=, /=, %=) on a variable.
10. Write a Python program to simulate the behavior of increment and decrement operations (prefix and postfix style) using standard arithmetic.

Data Types

11. Write a Python program to declare variables of different data types, assign values to them, and print both their values and data types.
12. Write a Python program to convert a float value to an integer and print both the original float value and the converted integer value.
13. Write a Python program to demonstrate implicit type conversion in arithmetic operations.
14. Write a Python program to take a single character as input from the user and display its corresponding ASCII value.
15. Write a Python program to demonstrate overflow behavior with the char data type.

If/Else and Nested If

16. Write a Python program to find the largest among three numbers entered by the user.
17. Write a Python program to check whether a given integer is even or odd.
18. Write a Python program to check whether a given year is a leap year or not.
19. Write a Python program to grade a student based on their marks using nested if statements.
20. Write a Python program to check whether a given number is positive, negative, or zero.

Switch Case

21. Write a Python program to create a simple calculator that can perform basic arithmetic operations: addition, subtraction, multiplication, and division.
22. Write a Python program to display the day of the week based on user input (1 to 7) using if-elif-else conditions.
23. Write a Python program to check whether an entered alphabet is a vowel or a consonant.
24. Write a Python program to check whether a given integer is even or odd.
25. Write a Python program that displays a menu to perform addition or subtraction of two numbers.

Loops & Nested Loops

26. Write a C program to print numbers from 1 to 10 using a for loop.
27. Write a Python program to calculate and print the factorial of a given positive integer using a while loop.
28. Write a Python program to print all even numbers from 1 to 20 using a loop.
29. Write a Python program to print the multiplication table of a given number using a loop.
30. Write a Python program to print a square pattern of stars (*) using nested loops.

Star Pattern - Nested Loops

31. Write a Python program to print a left-aligned triangle pattern of stars (*) using nested loops.
32. Write a Python program to print a right-aligned triangle pattern of stars (*) using nested loops.
33. Write a Python program to print a pyramid pattern of stars (*) using nested loops.
34. Write a Python program to print an inverted pyramid pattern of stars (*) using nested loops.
35. Write a Python program to print a hollow square pattern of stars (*) using nested loops.

Arrays

36. Write a Python program to declare an integer array, initialize it with values, and display the elements.
37. Write a Python program to find the sum of all elements in an integer array.
38. Write a Python program to find the largest element in an array of integers.
39. Write a Python program to reverse the elements of an integer array.
40. Write a Python program to count the number of even and odd elements in an integer array.

Strings

41. Write a Python program to input a string from the user and display it on the screen.
42. Write a Python program to find and display the length of a given string.
43. Write a Python program to input two strings from the user and concatenate them into one.
44. Write a Python program to input a string from the user and copy its contents into another string.
45. Write a Python program to input two strings from the user and compare them to determine if they are equal.

Arrays

46. Write a Python program to declare and initialize an array (list), then display its elements.
47. Write a Python program to input elements into a list, calculate the sum of all elements, and display the result.
48. Write a Python program to input elements into a list, calculate the maximum of all elements, and display the result.
49. Write a Python program to input elements into a list and display the list in reverse order.
50. Write a Python program to input elements into a list and count how many elements are even and how many are odd.

Strings

51. Write a Python program to take a string input from the user and print it on the screen.
52. Write a Python program to input a string from the user and find its length without using the built-in len() function.
53. Write a Python program to input two strings from the user and concatenate (join) the second string to the end of the first string. Then print the combined string.
54. Write a Python program to input a string from the user and copy it into another variable. Then print the copied string.
55. Write a Python program to input two strings from the user and compare them to check if they are equal or not. Display an appropriate message.
\

Pointers

56. Write a Python program to declare an integer variable, assign it a value, and print its memory address using the id() function.
57. Write a Python program to declare an integer variable, assign a value, and use a reference (simulating a pointer) to access and print the value.
58. Write a Python program to swap the values of two integer variables using a function that takes them as references.
59. Write a Python program to declare an integer list, use index-based access to simulate pointer traversal, and print all the elements.
60. Write a Python program to simulate pointer arithmetic by traversing a list using a loop variable instead of indexing directly.

Functions

61. Write a Python program to simulate pointer arithmetic by traversing a list using a loop variable and printing elements without direct indexing.
62. Write a Python program to create a function that takes two integers, adds them, and returns the sum. Call this function and print the result.
63. Write a Python program to calculate the factorial of a given non-negative integer using recursion.
64. Write a Python program that defines a function to check whether a given integer is a prime number.
65. Write a Python program that uses a function to generate and print the Fibonacci series up to n terms. The function should take an integer n as an argument and print the Fibonacci sequence up to n terms. Call this function from main() after taking input from the user.