NAME- ARYAN SINGH PANWAR
ROLL NO. - 10
CLASS- XI D
COMPUTER SCIENCE PRACTICAL FILE
WAP to swap/exchange values of two variables.
O1
A cloth showroom has announced the
Q2 following festival discounts and the assured
gifts on the purchase of items, based on the
total cost of the items purchased.
Write a Python code to input the total cost of
the items purchased. Calculate and display the
discount and the amount to be paid along with
the assured gift.
WAP to print largest number among three
Q3 numbers.
WAP to check whether an entered number is
Q4 prime number or not.
WAP to check whether an entered number is a
Q5 palindrome number or not.
WAP to print the terms of Fibonacci series.
Q6
WAP to print the following patterns:
Q7
a)
*
**
***
****
b)
A
AB
ABC
ABCD
c)
1
12
123
1234
12345
WAP to count and display the number of
Q8 vowels, consonants, uppercase, lowercase
characters in a string.
WAP to input a string and determine whether it
Q9 is a palindrome string or not.
Q10 WAP which replaces all vowels in the given
string with '*'.
Q1) WAP to swap/exchange values of two variables.
# Python program to swap two variables
x = int (input('Enter value of x: '))
y = int (input('Enter value of y: '))
x=y
y=x
print('The value of x after swapping: {}'.format(x))
print('The value of y after swapping: {}'.format(y))
output:
Enter value of x: 30
Enter value of y: 30
The value of x after swapping: 30
The value of y after swapping: 30
**********************************************************************************
**********************************************************************************
Q2) A cloth showroom has announced the following festival discounts and the assured gifts on the
purchase of items, based on the total cost of the items purchased.
Total Cost Discount Assured Gift
Less than or upto Rs. 2000 5% Wall Clock
Rs. 2001 to Rs. 5000 10% School Bag
Rs. 5001 to Rs. 10,000 15% Electronic Iron
More than Rs. 10,000 20% Wrist Watch
Write a Python code to input the total cost of the items purchased. Calculate and display the
discount and the amount to be paid along with the assured gift.
# input sale amount
amt = int(input("Enter Sale Amount: "))
# checking conditions and calculating discount
if(amt>0):
if amt<=5000:
disc = amt*0.05
print ("assured gift is wall clock")
elif amt<=15000:
disc=amt*0.12
print ("assured gift is school bag ")
elif amt<=25000:
disc=0.2 * amt
print ("assured gift is electronic iron ")
else:
disc=0.3 * amt
print ("assured gift is wrist watch")
print("Discount : ",disc)
print("Net Pay : ",amt-disc)
else:
print("Invalid Amount")
output:
Enter Sale Amount: 3000
assured gift is wall clock
Discount : 150.0
Net Pay : 2850.0
**********************************************************************************
**********************************************************************************
Q3) WAP to print largest number among three numbers.
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
num3 = float(input("Enter third number: "))
if (num1 > num2) and (num1 > num3):
largest = num1
elif (num2 > num1) and (num2 > num3):
largest = num2
else:
largest = num3
print("The largest number is",largest)
output:
Enter first number: 40
Enter second number: 43
Enter third number: 53
The largest number is 53.0
**********************************************************************************
**********************************************************************************
Q4) WAP to check whether an entered number is prime number or not.
# Program to check if a number is prime or not
num = int(input("Enter a number: "))
flag = False
if num == 1:
print(num, "is not a prime number")
elif num > 1:
for i in range(2, num):
if (num % i) == 0:
flag = True
break
if flag:
print(num, "is not a prime number")
else:
print(num, "is a prime number")
output:
Enter a number: 29
29 is a prime number
**********************************************************************************
**********************************************************************************
Q5) WAP to check whether an entered number is a palindrome number or not.
num = int(input("enter a no."))
temp = num
reverse = 0
while temp > 0:
remainder = temp % 10
reverse = (reverse * 10) + remainder
temp = temp // 10
if num == reverse:
print('Palindrome')
else:
print("Not Palindrome")
output:
enter a no.30
Not Palindrome
**********************************************************************************
**********************************************************************************
Q6) WAP to print the terms of Fibonacci series.
# Program to display the Fibonacci sequence up to n-th term
nterms = int(input("How many terms? "))
n1, n2 = 0, 1
count = 0
if nterms <= 0:
print("Please enter a positive integer")
elif nterms == 1:
print("Fibonacci sequence upto",nterms,":")
print(n1)
else:
print("Fibonacci sequence:")
while count < nterms:
print(n1)
nth = n1 + n2
n1 = n2
n2 = nth
count += 1
output:
How many terms? 5
Fibonacci sequence:
**********************************************************************************
**********************************************************************************
Q7) WAP to print the following patterns:
(a)
*
**
***
****
rows = 4
for i in range(0, rows):
# nested loop for each column
for j in range(0, i + 1):
# print star
print("*", end=' ')
# new line after each row
print("\r")
output:
*
**
***
****
**********************************************************************************
(B)
A
AB
ABC
ABCD
n=4
for i in range(1,n+1):
A = 97
for j in range(1, i+1):
print("%c" %(A), end="")
A += 1
print()
output:
A
AB
ABC
ABCD
**********************************************************************************
(C)
12345
1234
123
12
1
for i in range(6, 1, -1):
for j in range(1, i):
print(j, end="")
print()
output:
12345
1234
123
12
1
**********************************************************************************
**********************************************************************************
Q8) WAP to count and display the number of vowels, consonants, uppercase, lowercase
characters in a string.
string = input("Enter Your String : ")
vowels = consonants = uppercase = lowercase = 0
vowels_list = ['a','e','i','o','u','A','E','I','O','U']
for i in string:
if i in vowels_list:
vowels += 1
if i not in vowels_list:
consonants += 1
if [Link]():
uppercase += 1
if [Link]():
lowercase += 1
print("Number of Vowels in this String = ", vowels)
print("Number of Consonants in this String = ", consonants)
print("Number of Uppercase characters in this String = ", uppercase)
print("Number of Lowercase characters in this String = ", lowercase)
output:
Enter Your String : saksham
Number of Vowels in this String = 2
Number of Consonants in this String = 5
Number of Uppercase characters in this String = 0
Number of Lowercase characters in this String = 7
*************************************************************************
*************************************************************************
****************************************************************
Q9) WAP to input a string and determine whether it is a palindrome string or not.
string = input("Enter string")
revstr = ""
for i in string:
revstr = i + revstr
print("Reversed string ",revstr)
if(string == revstr):
print("The string is a palindrome.")
else:
print("The string is not a palindrome.")
output:
Enter stringrosary school
Reversed string loohcs yrasor
The string is not a palindrome.
**********************************************************************************
**********************************************************************************
Q10) WAP which replaces all vowels in the given string with '*'.
str = input("Enter the string: ")
newStr = ""
for ch in str :
lch = [Link]()
if lch == 'a' \
or lch == 'e' \
or lch == 'i' \
or lch == 'o' \
or lch == 'u' :
newStr += '*'
else :
newStr += ch
print(newStr)
output:
Enter the string: INDIA
*ND**
*********************************************
*********************************************