Python I
Python Beginner
A comprehensive course designed to introduce you to the world of programming using Python. Whether you have no prior coding experience or are looking to transition into Python from another language, this course is the perfect starting point. Throughout this beginner-friendly course, you will be guided step-by-step by experienced instructors who understand the challenges newcomers face. We will begin with an introduction to programming concepts and Python's syntax, ensuring a solid foundation for your coding journey.
Starting with the basics, you will learn about variables, data types, operators, and control flow structures like loops and conditionals. Through hands-on exercises and coding examples, you will gain practical experience in applying these concepts, reinforcing your learning along the way.
- Day 1
Concept:
Assignments:
Develop a basic Python program where a variable is defined to represent your favorite Pokemon, and the program prints a message acknowledging it.
Output:
My favorite Pokemon is Pikachu.
- Day 2
Concept:
Assignments:
Problem Statement:
Create a variable num and assign an integer value of your choice.
Print the data type of num using the type() function.
Output:
class 'int'
Explanation:
Let's suppose a variable num with the value 42,
The output shows that the data type of num is
- Day 3
Concept:
Assignments:
You are tasked with designing a Python program, define a two numbers num1 and num2 and execute the following operations:
1. Calculate and display the sum of the two numbers.
2. Determine and show the result of subtracting the second number from the first.
3. Compute and print the product of the two numbers.
4. Find the quotient of dividing the first number by the second and output the result.
Ensure your program handles potential edge cases gracefully, providing clear and concise output for each operation.
Output:
Let's suppose the first number: 8 and the second number: 3
1. Sum of the two numbers: 11
2. Result of subtraction: 5
3. Product of the two numbers: 24
4. Quotient of division: 2.6666666666666665
- Day 4
Concept:
Assignments:
Implement a Python function that define a person's age and generates distinct messages based on predefined conditions:
If the age is less than 18, the function should return "You are a minor.
If the age is between 18 and 65 (inclusive), the function should return "You are an adult.
If the age is greater than 65, the function should return "You are a senior citizen.
Output:
You are a minor.
You are an adult.
You are a senior citizen.
Explanation:
For age 15, 35 and 70.
- Day 5
Concept:
Assignments:
Write a program using a while loop to print all the numbers from 1 to 10.
Create a list of names. Use a for loop to iterate over the list and print a personalized greeting for each name.
Output:
1 2 3 4 5 6 7 8 9 10
Hello, Alice! Hello, Bob! Hello, Charlie! Hello, David! Hello, Eve!
Explanation:
This program utilizes a while loop to print numbers from 1 to 10 horizontally, separated by spaces. It then uses a for loop to print personalized greetings for each name horizontally, with each greeting separated by spaces.
- Day 6
Concept:
Assignments:
Design a Python program to execute division on two predefined numbers, while considering the possibility of a division by zero error. Ensure that the program handles this exception gracefully, providing a clear error message in such cases.
Output:
Error: Division by zero is not allowed.
Explanation:
The program takes two predetermined numbers and attempts to perform division. A try-except mechanism is implemented to catch and manage the ZeroDivisionError if the denominator is zero. In the event of such an error, the program displays a clear and informative message indicating that division by zero is not allowed.
- Day 7
Concept:
Assignments:
Define a Python function named is_even that takes an integer parameter and returns True if the provided number is even; otherwise, it returns False.
Output:
True
False
Explanation:
the function is_even is called two times with the parameter 8 and 9.
- Day 8
Concept:
Assignments:
Develop a Python program to concatenate two lists into a single list, adhering to the following requirements:
1. Define two distinct lists.
2. Design a function that accepts both lists as parameters and return a new list comprising elements from both input lists.
3. Print the resulting concatenated list.
Output:
[1, 2, 3, 'a', 'b', 'c']
Explanation:
The function concatenate_lists is applied to the lists [1, 2, 3] and ['a', 'b', 'c'].
- Day 9
Concept:
Assignments:
Compose a Python program to execute various operations on a given dictionary:
1. Insert a new key-value pair into the dictionary.
2. Delete a designated key-value pair from the dictionary.
3. Modify the value associated with a specified key in the dictionary.
4. Verify the existence of a key in the dictionary.
5. Display all the keys present in the dictionary.
Output:
{'a': 1, 'b': 2, 'c': 3, 'd': 4}
{'a': 1, 'c': 3, 'd': 4}
{'a': 10, 'c': 3, 'd': 4}
True
['a', 'c', 'd']
Explanation:
1. Adding a new key-value pair: The dictionary after adding the pair is {'a': 1, 'b': 2, 'c': 3, 'd': 4}.
2. Removing a specific key-value pair: The dictionary after removing the key 'b' is {'a': 1, 'c': 3, 'd': 4}.
3. Updating the value of a specific key: After updating the value of key 'a' to 10, the dictionary becomes {'a': 10, 'c': 3, 'd': 4}.
4. Checking if a key exists: The existence of the key 'c' in the dictionary is confirmed (Output: True).
5. Printing all keys in the dictionary: The list of all keys in the dictionary is ['a', 'c', 'd'].
- Day 10
Concept:
Assignments:
Develop a Python program to perform conversions between a list and a set, adhering to the following requirements:
1. Define a list with some elements.
2. Design a function that converts the list into a set.
3. Design another function that converts a set into a list.
4. Print both the converted list and set.
Output:
{1, 2, 3, 4, 5}
[1, 2, 3, 4, 5]
Explanation:
1. The initial list [1, 2, 3, 3, 4, 5] is converted into a set.
2. The set {1, 2, 3, 4, 5} is then converted back into a list
- Day 11
Concept:
Resources:
Assignments:
Problem Statement:
Develop a Python program for a number guessing game with the following requirements:
1. Random Number Generation: Utilize the `random` library to generate a random number between 1 and 100.
2. Guess Attempts: The player should be allowed 1 attempt to guess the number.
3. Feedback Mechanism: After each guess, the program should provide feedback to the player:
- If the guessed number is higher than the random number, display "Too high!"
- If the guessed number is lower than the random number, display "Too low!"
- If the guessed number matches the random number, display a congratulatory message.
This program will simulate a fun and interactive game where players can practice their guessing skills within a limited number of attempts, leveraging Python's `random` library for randomness.