Q1).
WAP to print the following in the same manner:
Python is a high-level programming language.
Python is a general-purpose programming language.
Python is dynamically typed and garbage-collected.
Python is designed by Guido Van Rossum.
ANS:-
INPUT-
text = "Python is a high-level programming language."
print(text)
text = " Python is a general-purpose programming language."
print(text)
text = "Python is dynamically typed and garbage-collected."
print(text)
text = " Python is designed by Guido Van Rossum."
print(text)
OUTPUT-
Python is a high-level programming language.
Python is a general-purpose programming language.
Python is dynamically typed and garbage-collected.
Python is designed by Guido Van Rossum.
Q2). WAP to input two numbers. Swap their values and print the values
ANS:-
INPUT-
num1 = float(input("Enter the first number: "))
num2 = float(input("Enter the second number: "))
temp = num1
num1 = num2
num2 = temp
print("After swapping:")
print("First number:", num1)
print("Second number:", num2)
OUTPUT-
Enter the first number: 9
Enter the second number: 7
After swapping:
First number: 7.0
Second number: 9.0
Q3). WAP to input a number (grams) and print its equivalent value in
Kilogram
ANS:-
INPUT-
grams = float(input("Enter the weight in grams: "))
kilograms = grams / 1000
print("The equivalent weight in kilograms is:", kilograms, "kg")
OUTPUT-
Enter the weight in grams: 4
The equivalent weight in kilograms is: 0.004 kg
Q4). WAP to input two strings and print # at the end of each string.
ANS:-
INPUT-
string1 = input("Enter the first string: ")
string2 = input("Enter the second string: ")
string1_with_hash = string1 + '#'
string2_with_hash = string2 + '#'
print("First string with '#' at the end:", string1_with_hash)
print("Second string with '#' at the end:", string2_with_hash)
OUTPUT-
Enter the first string: 6
Enter the second string: 8
First string with '#' at the end: 6#
Second string with '#' at the end: 8#
Q5). WAP to input an age of a person and check whether the person is eligible
for pension or not.
ANS:-
INPUT-
age = int(input("Enter the age of the person: "))
pension_eligibility_age = 60
if age >= pension_eligibility_age:
print("The person is eligible for a pension.")
else:
print("The person is not eligible for a pension.")
OUTPUT-
Enter the age of the person: 18
The person is not eligible for a pension.
Q6).WAP to input percentage (in number) of a student and calculate the grade
as per following:
Grade A more than 85
Grade B 75-84
Grade C 65-74
Grade D 55-64
Grade F below 5
the grade as per following:
Grade A more than 85
Grade B 75-84
Grade C 65-74
Grade D 55-64
Grade F below 5
ANS:-
INPUT-
percentage = float(input("Enter the student's percentage: "))
if percentage > 85:
grade = "A"
elif 75 <= percentage <= 84:
grade = "B"
elif 65 <= percentage <= 74:
grade = "C"
elif 55 <= percentage <= 64:
grade = "D"
else:
grade = "F"
print("The student's grade is:", grade)
OUTPUT-
Enter the student's percentage: 76
The student's grade is: B
Q7). WAP to print multiples of seven from 1 to 100.
ANS:-
INPUT-
for i in range(1, 101):
if i % 7 == 0:
print(i)
OUTPUT-
14
21
28
35
42
49
56
63
70
77
84
91
98
Q8). WAP to print numbers 100-1 in reverse order using while loop.
ANS:-
INPUT-
number = 100
while number >= 1:
print(number)
Q9). WAP to print the following pattern:
AB
ABC
ABCD
ABCDE
ANS:-
INPUT-
n = int(input("Enter number of rows: "))
for i in range(1,n+1):
a = 97
for j in range(1, i+1):
print("%c" %(a), end="")
a += 1
print()
OUTPUT-
ab
abc
abcd
abcde
Q10). WAP to create a list of numbers and print the following:
a) Sum of all elements
b) Maximum element
c) Minimum element
ANS:-
INPUT-
numbers = [23, 45, 12, 67, 8, 34]
total = sum(numbers)
print("Sum of all elements:", total)
maximum = max(numbers)
print("Maximum element:", maximum)
minimum = min(numbers)
print("Minimum element:", minimum)
OUTPUT-
Sum of all elements: 189
Maximum element: 67
Minimum element: 8
Q11). WAP to input a list of strings. Sort the list in both ascending order and
descending order
ANS:-
INPUT-
string_list = input("Enter a list of strings separated by spaces: ").split()
ascending_sorted_list = sorted(string_list)
descending_sorted_list = sorted(string_list, reverse=True)
print("Ascending order:", ascending_sorted_list)
print("Descending order:", descending_sorted_list)
OUTPUT-
Enter a list of strings separated by spaces: 67 12 45 87 34 1 2 76 09
Ascending order: ['09', '1', '12', '2', '34', '45', '67', '76', '87']
Descending order: ['87', '76', '67', '45', '34', '2', '12', '1', '09']