0% found this document useful (0 votes)
3 views2 pages

Python Basics With Code

The document contains basic Python practical questions along with their answers. It covers fundamental programming concepts such as printing, user input, conditionals, loops, functions, and data structures. Each example demonstrates a specific task, like checking even or odd numbers, finding the largest of three numbers, and calculating factorials.

Uploaded by

ajaykumarjagat07
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

Python Basics With Code

The document contains basic Python practical questions along with their answers. It covers fundamental programming concepts such as printing, user input, conditionals, loops, functions, and data structures. Each example demonstrates a specific task, like checking even or odd numbers, finding the largest of three numbers, and calculating factorials.

Uploaded by

ajaykumarjagat07
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Python Basic Practical Questions with Answers

1. Print Hello World


print("Hello, World!")

2. Add two numbers (input from user)


a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
print("Sum:", a + b)

3. Check even or odd


num = int(input("Enter a number: "))
if num % 2 == 0:
print("Even")
else:
print("Odd")

4. Find largest of three numbers


a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
c = int(input("Enter third number: "))
if a >= b and a >= c:
print("Largest is", a)
elif b >= c:
print("Largest is", b)
else:
print("Largest is", c)

5. Print multiplication table of a number


n = int(input("Enter a number: "))
for i in range(1, 11):
print(n, "x", i, "=", n * i)

6. Check if string is palindrome


s = input("Enter a string: ")
if s == s[::-1]:
print("Palindrome")
else:
print("Not Palindrome")

7. Function to find square of number


def square(n):
return n * n
print("Square is:", square(5))

8. List and loop to print elements


lst = [10, 20, 30, 40, 50]
for item in lst:
print(item)

9. Factorial using loop


num = int(input("Enter a number: "))
fact = 1
for i in range(1, num + 1):
fact *= i
print("Factorial:", fact)

10. Swap two numbers


a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
a, b = b, a
print("After swapping: a =", a, ", b =", b)

You might also like