Learning coding means GreatToCode Be more than a Coder ! Greattocode , Join GreatToCode Community,1000+ Students Trusted On Us .If You want to learn coding, Then GreatToCode Help You.No matter what It Takes !


CODE YOUR WAY TO A MORE FULFILLING And HIGHER PAYING CAREER IN TECH, START CODING FOR FREE Camp With GreatToCode - Join the Thousands learning to code with GreatToCode
Interactive online coding classes for at-home learning with GreatToCode . Try ₹Free Per Month Coding Classes With The Top Teachers . Python Basics Practices

Python Basics Practices

Become More Then A coder | Learn & Start Coding Now.

🔹 Problem 1: Print a welcome message

Task: Write a program that prints:
Welcome to Python, Arvind!

Answer:

print("Welcome to Python, Arvind!")

🔹 Problem 2: Use variables to store and print your name and age

Task: Store your name in a variable and age in another, then print them.

Answer:

name = "Arvind"
age = 25
print("My name is", name, "and I am", age, "years old.")

🔹 Problem 3: Take user input and greet them

Task: Ask the user for their name and print a greeting.

Answer:

# name = input("What is your name? ")
# print("Hello, " + name + "! Welcome.")

🔹 Problem 4: Use if to check voting eligibility

Task: If age is 18 or more, print "You can vote", else "You cannot vote".

Answer:

age = 17

if age >= 18:
    print("You can vote.")
else:
    print("You cannot vote.")

🔹 Problem 5: Print all items in a list

Task: Print every fruit in this list: ["apple", "banana", "cherry"]

Answer:

fruits = ["apple", "banana", "cherry"]
for fruit in fruits:
    print(fruit)

🔹 Problem 6: Create a function to multiply two numbers

Task: Write a function multiply(a, b) that returns the product.

Answer:

def multiply(a, b):
    return a * b

print("Product:", multiply(4, 5)) # Output: 20

🔹 Problem 7: Use a dictionary to store student data

Task: Store name, age, and grade in a dictionary. Print each key and value.

Answer:

student = {
    "name": "Arvind",
    "age": 25,
    "grade": "A"
}

for key, value in student.items():
    print(key, ":", value)

🔹 Problem 8: Print index with items using enumerate()

Task: Print index and value for each subject in a list.

Answer:

subjects = ["Math", "Science", "English"]

for index, subject in enumerate(subjects):
    print(index, "→", subject)

🔹 Problem 9: Handle division by zero

Task: Ask for a number and divide 100 by it. Catch any errors.

Answer:

try:
    # num = int(input("Enter a number: "))
    num = 0
    result = 100 / num
    print("Result:", result)
except ZeroDivisionError:
    print("Cannot divide by zero.")
except ValueError:
    print("Please enter a valid number.")

🔹 Problem 10: Use nested loops to print a pattern

Task: Print a pattern of stars like:

*
* *
* * *

Answer:

for i in range(1, 4): # 1 to 3
    for j in range(i): # print i stars
        print("*", end=" ")
    print() # new line

✅ Summary of Skills Practiced

Skill Practiced

print() ✅
Variables ✅
input() ✅
if-else ✅
Lists & Loops ✅
Functions ✅
Dictionaries ✅
enumerate() ✅
try-except ✅
Nested loops ✅

Post a Comment

0 Comments

•Give The opportunity to your child with GreatToCode Kid's • Online Coding Classes for Your Kid • Introduce Your kid To the world's of coding
•Fuel You Career with our 100+ Hiring Partners, Advance Your Career in Tech with GreatToCode. •Join The Largest Tech and coding Community and Fast Forward Your career with GreatToCode. •10000+ Learner's+ 90 % placement Guarantee. • Learning Coding is Better with the GreatToCode community .
•Greattocode Kid's •GreatToCode Career •GreatToCode Interview •GreatToCode Professional •GreatToCode for schools •GreatToCode For colleges •GreatToCods For Businesses.
Are you ready to join the millions of people learning to code? GreatToCode Pass is your one-stop-shop to get access to 1000+ courses, top-notch support, and successful job placement. What are you waiting for? Sign up now and get your future in motion with GreatToCode Pass.