1. Hello WorldProblem StatementWrite a Python program that prints "Hello, World!" to the console.ApproachThis is the most basic Python program. Use the print() function to output text.Solutionprint("Hello, World!")
2. Variable AssignmentProblem StatementCreate a variable named 'age' and assign it the value 25. Then print the variable.ApproachVariables in Python are created by assignment. Use the print() function to display the value.Solutionage = 25 print(age)
3. String ConcatenationProblem StatementCreate two variables: first_name = "John" and last_name = "Doe". Concatenate them with a space in between and print the full name.ApproachYou can concatenate strings using the + operator. Don't forget to add a space between the names.Solutionfirst_name = "John" last_name = "Doe" full_name = first_name + " " + last_name print(full_name)
4. Basic ArithmeticProblem StatementWrite a program that calculates and prints the sum of 15 and 27.ApproachUse the + operator for addition and print() to display the result.Solutionresult = 15 + 27 print(result)
5. User InputProblem StatementWrite a program that asks the user for their name and then prints "Hello, [name]!"ApproachUse the input() function to get user input, then use string concatenation or f-strings to create the greeting.Solution`name = input("What is your name? ") print(f"Hello, {name
6. Type ConversionProblem StatementAsk the user for their age (which will be a string), convert it to an integer, and print their age plus 5.Approachinput() returns a string. Use int() to convert it to an integer before performing arithmetic.Solutionage = input("Enter your age: ") age_int = int(age) print(age_int + 5)
7. If StatementProblem StatementWrite a program that checks if a number (stored in variable 'num') is greater than 10. If it is, print "Greater than 10".ApproachUse an if statement to check the condition. Remember proper indentation in Python.Solutionnum = 15 if num > 10: print("Greater than 10")
8. If-Else StatementProblem StatementWrite a program that checks if a number is even or odd. Print "Even" or "Odd" accordingly.ApproachUse the modulo operator (%) to check if a number is divisible by 2. If num % 2 == 0, it's even.Solutionnum = 7 if num % 2 == 0: print("Even") else: print("Odd")
9. For LoopProblem StatementWrite a program that prints numbers from 1 to 5 using a for loop.ApproachUse range(1, 6) to generate numbers from 1 to 5. The second argument is exclusive.Solutionfor i in range(1, 6): print(i)
10. While LoopProblem StatementWrite a program that prints numbers from 1 to 5 using a while loop.ApproachInitialize a counter variable, check the condition, and increment the counter inside the loop.Solutioncount = 1 while count <= 5: print(count) count += 1
11. List CreationProblem StatementCreate a list containing the numbers 1, 2, 3, 4, 5 and print it.ApproachLists in Python are created using square brackets [].Solutionnumbers = [1, 2, 3, 4, 5] print(numbers)
12. List IndexingProblem StatementGiven the list fruits = ["apple", "banana", "cherry"], print the second element.ApproachPython uses zero-based indexing. The second element is at index 1.Solutionfruits = ["apple", "banana", "cherry"] print(fruits[1])
13. List AppendProblem StatementCreate an empty list, then add the numbers 10, 20, and 30 to it using the append() method. Print the final list.ApproachUse the append() method to add elements to a list one at a time.Solutionnumbers = [] numbers.append(10) numbers.append(20) numbers.append(30) print(numbers)
14. String LengthProblem StatementWrite a program that finds and prints the length of the string "Python Programming".ApproachUse the len() function to get the length of a string.Solutiontext = "Python Programming" print(len(text))
15. String MethodsProblem StatementConvert the string "hello world" to uppercase and print it.ApproachUse the upper() method on strings to convert them to uppercase.Solutiontext = "hello world" print(text.upper())
16. Function DefinitionProblem StatementDefine a function called greet() that prints "Hello!" when called. Then call the function.ApproachUse the def keyword to define a function. Don't forget to call it after defining.Solutiondef greet(): print("Hello!") greet()
17. Function with ParameterProblem StatementDefine a function called greet_name(name) that prints "Hello, [name]!". Call it with your name.ApproachFunctions can accept parameters. Use the parameter inside the function body.Solution`def greet_name(name): print(f"Hello, {name
18. Function Return ValueProblem StatementDefine a function called add(a, b) that returns the sum of two numbers. Call it with 5 and 3, and print the result.ApproachUse the return keyword to return a value from a function.Solutiondef add(a, b): return a + b result = add(5, 3) print(result)
19. Dictionary CreationProblem StatementCreate a dictionary with keys "name" and "age", with values "John" and 25 respectively. Print the dictionary.Approach`Dictionaries use curly braces {Solution`person = {"name": "John", "age": 25
20. Dictionary AccessProblem Statement`Given the dictionary person = {"name": "Alice", "age": 30ApproachAccess dictionary values using square brackets with the key.Solution`person = {"name": "Alice", "age": 30