Python Practice Questions (Variables, Strings, Input)
1. Create a variable `x` and assign it the value 10.
2. Swap the values of two variables `a = 5` and `b = 10`.
3. Create a variable `name` and assign your name to it. Print it.
4. Assign the result of 20 divided by 4 to a variable `result`.
5. Assign your age to a variable and then add 5 to it.
6. Define two variables and print their product.
7. Assign a string to a variable and print its type.
8. Create a variable to store the result of 3 squared.
9. Store the result of 5 + 3 * 2 in a variable and print it.
10. Create variables `length` and `width` and calculate the area of a rectangle.
11. Print 'My name is John and I am 25' using an f-string.
12. Print the same sentence using `.format()` method.
13. Use `.format()` to insert values into: 'The {} costs Rs.{}'.
14. Use f-string to print the sum of two variables inside a sentence.
15. Use `.format()` with named placeholders to format a sentence.
16. Print a sentence with 3 variables using f-string.
17. Create a message with `.format()` using keyword arguments.
18. Use f-string to embed an expression like `5 * 3` inside a sentence.
19. Format a float number to 2 decimal places using f-string.
20. Use `.format()` to align text within a fixed width.
21. Remove leading and trailing spaces from a string.
22. Convert a string to uppercase.
23. Convert a string to lowercase.
24. Replace a word in a sentence with another word.
25. Count the number of times 'a' appears in a string.
26. Find the index of the word 'Python' in a string.
27. Check if a string starts with 'Hello'.
28. Check if a string ends with 'World'.
29. Split a sentence into words.
30. Join a list of words into a sentence.
31. Capitalize the first letter of each word in a sentence.
32. Use `.isnumeric()` to check if a string is a number.
33. Use `.isalpha()` to check if a string contains only letters.
34. Reverse a string using slicing.
35. Remove all spaces from a string.
36. Take two numbers from the user and print their sum.
37. Use `eval()` to calculate a user-entered math expression.
38. Take name and age using input and print a greeting.
39. Use `input()` to take a sentence and count the words.
40. Read a number from input, square it, and print the result.
41. Use `eval()` to compute the area of a circle from user input.
42. Take a number input from user and check if its even or odd.
43. Ask the user to enter a list and convert it using `eval()`.
44. Take three numbers from input and print the largest.
45. Take a string input and print it in uppercase.
46. Ask the user to enter a sentence and count vowels in it.
47. Read a user's name and greet them with f-string.
48. Take input in the format 'a,b' and split into two variables.
49. Ask for a string and check if it is a palindrome.
50. Take a sentence and print each word on a new line.