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

Python_Basic_Constructs_Assignment_with_Answers

The document contains a Python assignment focused on basic constructs, including variable declaration, user input, control structures, functions, and list operations. It provides a series of questions with corresponding code snippets that demonstrate various programming concepts. Each question addresses a specific task, such as checking for even/odd numbers, calculating the area of a rectangle, and manipulating strings and lists.

Uploaded by

pardeep11ari
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)
5 views2 pages

Python_Basic_Constructs_Assignment_with_Answers

The document contains a Python assignment focused on basic constructs, including variable declaration, user input, control structures, functions, and list operations. It provides a series of questions with corresponding code snippets that demonstrate various programming concepts. Each question addresses a specific task, such as checking for even/odd numbers, calculating the area of a rectangle, and manipulating strings and lists.

Uploaded by

pardeep11ari
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

Assignment – Python Basic Constructs (With

Answers)
Course: Ihub ACP DA-B-BC=242804 (Python Basics)

Q1. Declare variables and print their types:


student_name = "Riya" student_age = 21 student_score = 87.5 is_passed = True
print(type(student_name)) print(type(student_age)) print(type(student_score))
print(type(is_passed))

Q2. Take user input and print greeting:

name = input("Enter your name: ") age = input("Enter your age: ") print(f"Hello
{name}! You are {age} years old.")

Q3. Check if number is even, odd, and divisible by 4:

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


print("Also divisible by 4") else: print("Odd")

Q4. Print numbers from 1 to 15:

for i in range(1, 16): print(i)

Q5. Print multiplication table:


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

Q6. Sum of odd numbers from 1 to 50:

i = 1 sum_odd = 0 while i <= 50: if i % 2 != 0: sum_odd += i i += 1 print("Sum:",


sum_odd)

Q7. Function to check prime number:

def check_prime(num): if num < 2: return False for i in range(2, int(num ** 0.5) +
1): if num % i == 0: return False return True

Q8. Function to calculate area of rectangle:

def calculate_area(length, width): return length * width

Q9. Function to greet user:

def greet_user(name): print(f"Welcome, {name}! Have a great day.")

Q10. List operations:

fruits = ["apple", "banana", "cherry", "kiwi", "mango"] print(fruits[0])


print(fruits[-1]) fruits.append("orange") fruits.remove("banana") print(fruits)
Q11. String reverse and vowel count:
text = input("Enter a string: ") print("Reversed:", text[::-1]) vowels =
"aeiouAEIOU" count = sum(1 for char in text if char in vowels) print("Vowel Count:",
count)

Q12. Fibonacci series up to n terms:

n = int(input("Enter n: ")) a, b = 0, 1 for _ in range(n): print(a, end=" ") a, b =


b, a + b

Q13. Count words, characters, and spaces:


sentence = input("Enter a sentence: ") words = sentence.split() word_count =
len(words) char_count = len(sentence) space_count = sentence.count(" ")
print("Words:", word_count) print("Characters:", char_count) print("Spaces:",
space_count)

You might also like