0% found this document useful (0 votes)
2 views17 pages

Python Programs

The document outlines various programming tasks including relational and logical operations, arithmetic calculations, and geometric calculations using Python. It provides examples of user input handling, mathematical operations, and control flow structures like loops and conditionals. Each task is accompanied by sample code and expected output to illustrate the functionality.

Uploaded by

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

Python Programs

The document outlines various programming tasks including relational and logical operations, arithmetic calculations, and geometric calculations using Python. It provides examples of user input handling, mathematical operations, and control flow structures like loops and conditionals. Each task is accompanied by sample code and expected output to illustrate the functionality.

Uploaded by

nsp.navya
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

CH - 7

No Statment Program Output


1. Working of a=20 True
Relational b=30 False
operators c=20 True
print(a<b) True
print(a>b) False
print(a<=b) True
print(a!=b) False
print(a==b)
print(a==c)
print(a==b)

2. Basic #taking two numbers from user The first no. =30
arthematic a=int(input("The first no. =")) The second no. =5
operation b=int(input("The second no. =")) The sum of two numbers = 35
#adding two numbers The difference of two numbers
res=a+b = 25
print("The sum of two numbers =", res) The product of two numbers =
#subtratcting two numbers 150
res=a-b The quotient of two numbers =
print("The difference of two numbers =", res) 6.0
#multiplying two numbers The quotient of floor division of
res=a*b two numbers = 6
print("The product of two numbers =", res) The remainder of two numbers
#dividing two numbers =0
res=a/b 30 raised to the power 5 =
print("The quotient of two numbers =", res) 24300000
#floor division of two numbers
res=a//b
print("The quotient of floor division of two
numbers =", res)
#finding remainder of two numbers
res=a%b
print("The remainder of two numbers =", res)
#raising a number
res=a**b
print(a, "raised to the power", b, "=", res)

3. Marks #accepting values from user Marks in 1st subject =99


calculation m1=int(input("Marks in 1st subject =")) Marks in 2nd subject =98
m2=int(input("Marks in 2nd subject =")) Marks in 3rd subject =97
m3=int(input("Marks in 3rd subject =")) Marks in 4rd subject =99
m4=int(input("Marks in 4rd subject =")) Marks in 5th subject =98
m5=int(input("Marks in 5th subject =")) Total marks obtained = 491
#finding total marks Average marks = 98.2
sum=m1+m2+m3+m4+m5 Percentage obtained = 98.2
#printing total marks
print("Total marks obtained =", sum)
#finding average
average=sum/5
#printing average
print("Average marks =", average)
#finding percentage
percentage=(sum/500)*100
#printing percentage
print("Percentage obtained =", percentage)
4. SI #accepting values from users Enter principle =10000
calculation p=int(input("Enter principle =")) Enter time period =5
t=int(input("Enter time period =")) Enter rate of interest =5
r=int(input("Enter rate of interest =")) The amount = 12500.0
#calculating si The si = 2500.0
si=(p*t*r)/100
#calculating amount
a=si+p
#printing amount
print("The amount =", a)
#printing si
print("The si =", si)
5. CI #accepting values from users Enter principle =100000
calculation p=int(input("Enter principle =")) Enter time period =5
t=int(input("Enter time period =")) Enter rate of interest =10
r=int(input("Enter rate of interest =")) The amount =
#calculating amount 161051.00000000006
a=p*(1+r/100)**t The ci = 61051.00000000006
#calculating ci
ci=a-p
#printing amount
print("The amount =", a)
#printing ci
print("The ci =", ci)
6. Cone- v, tsa, #accepting values from users Enter radius =20
csa r=int(input("Enter radius =")) Enter height =15
h=int(input("Enter height =")) The volume of cone = 6280.0
#assingning value of pie to p The curved surface area of cone
p=3.14 = 1570.0
#importing math The total surface area of the
import math cone = 2826.0
#finding the value of l
l=[Link](r*r+h*h)
#finding and printing the volume
v=1/3*p*r*r*h
print("The volume of cone =", v)
#finding and printing the csa
csa=p*r*l
print("The curved surface area of cone =", csa)
#finding and printing the tsa
tsa=p*r*(l+r)
print("The total surface area of the cone =", tsa)
7. Hemisphere- #accepting values from users Enter radius =15
v, tsa, csa r=int(input("Enter radius =")) The volume of hemispere =
#assingning value of pie to p 7065.0
p=3.14 The curved surface area of cone
#finding and printing the volume = 1413.0
v=2/3*p*r*r*r The total surface area of the
print("The volume of hemispere =", v) cone = 2119.5
#finding and printing the csa
csa=2*p*r*r
print("The curved surface area of cone =", csa)
#finding and printing the tsa
tsa=3*p*r*r
print("The total surface area of the cone =", tsa)
8. Using Heron #accepting values from user Enter the 1st side =13
Formula’s a=int(input("Enter the 1st side =")) Enter the 2nd side =14
to find area b=int(input("Enter the 2nd side =")) Enter the 3rd side =15
of triangle c=int(input("Enter the 3rd side =")) the area of the triangle = 84.0
#importing math
import math
#find the value of s
s=(a+b+c)/2
#finding the area using heron's formula
area=[Link](s*(s-a)*(s-b)*(s-c))
#printing the area
print("the area of the triangle =", area)

OR

a=int(input("Enter the 1st side ="))


b=int(input("Enter the 2nd side ="))
c=int(input("Enter the 3rd side ="))
if a+b>c and b+c>a and c+a>b:
import math
s=(a+b+c)/2
area=[Link](s*(s-a)*(s-b)*(s-c))
print("the area of the triangle =", area)
else:
print("Not a valid triangle")
9. Implement- #implenting the logical operators True
ing logical #Saving value False
operators a=20 False
b=30 False
c=20 True
#using not logical operator False
print(not(a>b)) True
#using and logical operator True
print(a>b and c>b) True
print(a>b and c<b)
print(a<b and c>b)
print(a<b and c<b)
#using or logical operator
print(a>b or c>b)
print(a>b or c<b)
print(a<b or c>b)
print(a<b or c<b)
Ch-8
No Satement Program Ouptput
1. Perform #Taking values Enter first no.= 56
arthemetic a=int(input("Enter first no.= ")) Enter second no.=5
operations b=int(input("Enter second no.=")) Enter 1 for +
using switch #printing commands Enter 2 for -
case print("Enter 1 for +") Enter 3 for *
print("Enter 2 for -") Enter 4 for /
print("Enter 3 for *") Enter 5 for //
print("Enter 4 for /") Enter 6 for %
print("Enter 5 for //") Enter 7 for **
print("Enter 6 for %") 6
print("Enter 7 for **") Remainder = 1
x=int(input())
#Using switch case
match x:
#entering different cases
case 1:
s=a+b
print("Sum =", s)
case 2:
d=a-b
print("Difference =", d)
case 3:
p=a+b
print("Product =", p)
case 4:
q=a/b
print("Quotient =", q)
case 5:
fd=a+b
print("Floor division =", fd)
case 6:
r=a%b
print("Remainder =", r)
case 7:
pw=a**b
print("power =", pw)
case default:
print("Invalid output")
st
2. To print 1 #using for loop 1
10 natural for i in range(1,11): 2
no. Using print(i) 3
loop. 4
5
6
7
8
9
10
3. Write the #taking value from user Enter a no. =5
table of a a=int(input("Enter a no. =")) 5*1=5
no. Given by #using for loop 5 * 2 = 10
the user for i in range(1,11): 5 * 3 = 15
print(a, "*", i, "=", a*i) 5 * 4 = 20
5 * 5 = 25
5 * 6 = 30
5 * 7 = 35
5 * 8 = 40
5 * 9 = 45
5 * 10 = 50
4. To print all #taking value from user Enter a no, =15
even no. Till n=int(input("Enter a no, =")) 2
a no. Given #using for loop 4
by user for i in range(2, n+1, 2): 6
print(i) 8
10
12
14
5. To check #taking value from user Enter a no, =34
whether a n=int(input("Enter a no, =")) Not a buzz no.
no. Is a buzz #using if-else statement
no. Or not. if n%10==7 or n%7==0:
[Buzz no. print("Buzz no.")
End with 7 else:
or is divisble print("Not a buzz no.")
by 7]
6. To find HCF #taking value from users Enter 1st no. =15
a=int(input("Enter 1st no. =")) Enter 2nd no. =3
b=int(input("Enter 2nd no. =")) HCF = 3
#assigning values
hcf=1
#using for loop and if statement
for i in range(2, a+1):
if a%i==0 and b%i==0:
hcf = i
print("HCF =", hcf)
7. To find the #taking value from user Enter a no. =1463
reverse of a=int(input("Enter a no. =")) No. entered by the user is :
no. print("No. entered by the user is :", a) 1463
r=0 Reversed no. = 3641
#using while loop
while a>0:
r=r*10+a%10
a=a//10
print("Reversed no. =", r)
8. Check #take input from user Enter a no. =121
whether a a=int(input("Enter a no. =")) No. entered by the user is : 121
palindrome print("No. entered by the user is :", a) Palindrome no.
no. #assigning values
[Pailndrome b=a
no is equal r=0
to its #using while loops
reverse] while a>0:
r=r*10+a%10
a=a//10
#using if-else statement
if b==r:
print("Palindrome no.")
else:
print("Not a palindrome no.")
9. To find the #take input from user Enter a no. =5
factorial of a a=int(input("Enter a no. =")) Factorial = 120
no. #assigning value
[Factorial is f=1
the product #using if-else statement
of every no. if a<0:
Except 0] f=0
else:
for i in range(1, a+1):
f=f*i
print("Factorial =", f)
10. To calculate #taking value from users Enter 1st no. =3
LCM a=int(input("Enter 1st no. =")) Enter 2nd no. =5
[HCF*LCM=a b=int(input("Enter 2nd no. =")) LCM = 15
*b] #assigning values
hcf=1
#using for loop and if statement
for i in range(2, a+1):
if a%i==0 and b%i==0:
hcf=i
lcm=(a*b)//hcf
print("LCM =", lcm)
11. To calculate #taking input from user Enter a no. =165
sum of n=int(input("Enter a no. =")) Sum of squares = 62
square of #assigning values
digits s=0
#using while loop
while n>0:
d=n%10
s=s+d*d
n=n//10
print("Sum of squTares =", s)
12. To check #Taking value from user Enter a no. =90
pronic no. n=int(input("Enter a no. =")) Pronic no.
[It is the status=False Enter a no. =90
product of 2 #using for loop Pronic no.
consecutive for i in range(1, n+1):
no.] if i*(i+1)==n: 2nd output [Not pronic]
status=True
break Enter a no. =5
#using if-else statement Not a pronic no.
if status==True: Enter a no. =5
print("Pronic no.")
else:
print("Not a pronic no.")

#Or

#Taking value from user


n=int(input("Enter a no. ="))
#using for loop and if-statement
for i in range(1, n+1):
if i*(i+1)==n:
print("Pronic no.")
break
13. To check a #taking user from user Enter a no.=204
duck no. n=int(input("Enter a no.=")) Duck no.
[It contains status=False
0] #using while loop anf if-else statement
while n>0:
if n%10==0:
status=True
break
else:
n=n//10
#using if-else statement
if status==True:
print("Duck no.")
else:
print("Not a duck no.")
14. To find the #Taking value from user Enter a no. =123
sum of digits a=int(input("Enter a no. =")) The sum= 6
s=0
#using while loop
while a>0:
s=s+a%10
a=a//10
print("The sum=", s)
15. To print no. #taking value from user Enter the no. of terms =4
Of fibonacci n=int(input("Enter the no. of terms =")) 0 1 1 2
sequence a=0
[sum of last b=1
2 no. 1st no. print(" ", a, " ", b," ", end='')
=1, 2nd no. c=0
=2] #using for loop
for i in range(3, n+1):
c=a+b
print("", c, end =' ')
a=b
b=c
16. To print no. #taking value from user Enter the no. of terms =5
Of tribonacci n=int(input("Enter the no. of terms =")) 0 1 2 3 6
sequence a=0
[sum of last b=1
3 no. 1st no. c=2
=1, 2nd no. print(" ", a, " ", b," ",c, " ", end='')
=2, 3rd no. = d=0
3] #using for loop
for i in range(4, n+1):
d=a+b+c
print("", d, end =' ')
a=b
b=c
c=d
17. To convert #taking value from user Enter a no. = 164
decimal no. n = int(input("Enter a no. = ")) Binary no. = 10100100
To binary no. #making b a string variable
b = ""
#using while loop
while n > 0:
b = str(n % 2) + b
n = n // 2
print("Binary no. =", b, "\t")

One given by sir is below


Doesn’t work

#taking value from user


n=int(input("Enter a no. ="))
#making b a string variable
b=""
#using while loop
while n>0:
b=n%2+b
n=n//2
18. To print the #taking value from user Enter a no. = 4
following n = int(input("Enter a no. = ")) * * * *
pattern- #using nested-for loop * * * *
* * * * for i in range (1, n+1): * * * *
* * * * for j in range(1, n+1): * * * *
* * * * print(" * ", end ="")
* * * * print()

Ch-9
No Satement Program Ouptput
1. F-7 of book #defining Enter speed =220
def speed(a): Demerit points = 30.0
if 70>=a: License suspended
print("OK")
else:
d=(a-70)/5
print("Demerit points =",d)
if d>12:
print("License suspended")
#taking value from user
a=int(input("Enter speed ="))
speed(a)
2. Write a #defining function Enter no. = 6
function that def speed(a): 14
returns the s=0
sum of for i in range(a + 1):
multiples of if i % 3 == 0 or i % 5 == 0:
3 and 5 s += i
between 0 return s
and the limit
For ex, if the #taking value from user
limit is 10, a = int(input("Enter no. = "))
then it print(speed(a))
returns the
sum of 3, 5,
6, 9, 10, that
is 33.
3. F-6 a=int(input("Enter a no. =")) Enter a no. =15
if a%3==0 and a%5==0: IceWater
print("IceWater")
else:
if a%3==0:
print("Ice")
elif a%5==0:
print("Water")
else:
print(a)
4. Prime or a = int(input("Enter a number: ")) Enter a number: 8
composite status=False Composite number
no. if a==0 or a==1:
print("Not prime nor composite")
else:
for i in range(2, a):
if a%i==0:
status=True
break

if status==True:
print("Composite no.")
else:
print("Prime no.")
5. Print the a=int(input("Enter 1st student's age=")) Enter 1st student's age=38
youngest b=int(input("Enter 2nd student's age=")) Enter 2nd student's age=43
and oldest c=int(input("Enter 3rd student's age=")) Enter 3rd student's age=5
age of if a>b and a>c: 2nd student is eldest
student from print("1st student is eldest") 3rd student is youngest
3 students. elif b>a and b>c:
print("2nd student is eldest")
else:
print("3rd student is eldest")

if a<b and a<c:


print("1st student is youngest")
elif b<a and b<c:
print("2nd student is youngest")
else:
print("3rd student is youngest")
6. Convert f=int(input("Enter the temperature in Enter the temperature in
fahrenheit to fahrenheit=")) fahrenheit=98
celcius c=(f-32)*5/9 The temperature in celcius=
C=(F-32)*5/9 print("The temperature in celcius=",c) 36.666666666666664

7. Create a list list=["Navya", "ATS Dolce", "Etc"] Navya


and tuple for i in list: ATS Dolce
and print all print(i) Etc
its elements tuple=(4,2,5) 4
for i in tuple: 2
print(i) 5
8. define a class class my_string: Enter: navya123@
to accept a def __init__(self, text): New string: mbuxb123@
string and [Link]=text
convert the
same to def convert(self):
uppercase, new_text=""
crate and for ch in [Link]:
display the if [Link]():
new string by if ch in "AEIOUaeiou":
replacing new_text+=chr(ord(ch)+1)
each vowel else:
by new_text+=chr(ord(ch)-1)
immediate else:
next letter new_text += ch
and every print("New string:", new_text)
covert by the
previous s = input("Enter: ")
character. obj = my_string(s)
the other [Link]()
characters
should
remain same
9. write a menu print("Menu:") Menu:
driven print("1. Display pattern 1") 1. Display pattern 1
program to print("2. Display pattern 2") 2. Display pattern 2
display the x=int(input("Choose 1 or 2:")) Choose 1 or 2:5
pattern as word = input("Enter a word: ").upper() Invalid Chice
per user's match x: Please choose either 1 or 2
choice using case 1:
match case if for i in range(len(word), 0, -1):
choice is print(word[:i])
pattern 1 case 2:
ABCDE ABCD for i in range(len(word)):
ABC AB A. If print(word[i] * (i + 1))
the choice is case default:
pattern 2 B print("Invalid Choice")
LL UUU EEEE print("Please choose either 1 or 2")
IF THE choice
is three print
a error
message
should be
displayed
8. Print a a=int(input("Enter the no.")) Enter the no.3
triangle for i in range(a): *
for j in range(i+1): * *
print(" * ", end='') * * *
print()
9. Print a a=int(input("Enter the no.")) Enter the no.3
inverted for i in range(a): * * *
triangle for j in range(a-i): * *
print(" * ", end='') *
print()
10. Print a a=int(input("Enter the no.")) Enter the no.4
sqaure for i in range(a): * * * *
for j in range(a): * * * *
print(" * ", end='') * * * *
print() * * * *

11. Print a rows = int(input("Enter the number of rows: ")) Enter the number of rows: 5
pyramid *
for i in range(rows): ***
print(" " * (rows - i - 1), end="") *****
print("*" * (2 * i + 1)) *******
*********
12. Leap year or year = int(input("Enter a year: ")) Enter a year: 2023
not 2023 is not a leap year.
if (year % 4 == 0 and year % 100 != 0) :
print(year, "is a leap year.")
elif(year % 400 == 0):
print(year, "is a leap year.")
else:
print(year, "is not a leap year.")
13. Swapping no. a=int(input("Enter 1st no.")) Enter 1st no.6
Using 3 b=int(input("Enter 2nd no.")) Enter 2nd no.4
variables c=a 1st no. is 4
a=b 2nd no. is 6
b=c
print("1st no. is", a)
print("2nd no. is", b)
14. Swapping no. a=int(input("Enter 1st no.")) Enter 1st no.5
Using 2 b=int(input("Enter 2nd no.")) Enter 2nd no.98
variables a=a+b 1st no. is 98
b=a-b 2nd no. is 5
a=a-b
print("1st no. is", a)
print("2nd no. is", b)
15. Print- r=int(input("Enter the no of rows:")) Enter the no of rows:4
1 for i in range(r): 1
12 for j in range(i+1): 12
123 print(j+1, end='') 123
1234 print() 1234
16. Print- r=int(input("Enter the no of rows:")) Enter the no of rows:4
1 for i in range(r): 1
22 for j in range(i+1): 22
333 print(i+1, end='') 333
4444 print() 4444
17. Print- r=int(input("Enter the no of rows:")) Enter the no of rows:4
1234 for i in range(r): 1234
123 for j in range(r-i): 123
12 print(j+1, end='') 12
1 print() 1
18. Print- r=int(input("Enter the no of rows:")) Enter the no of rows:4
4444 for i in range(r, 0, -1): 4444
333 for j in range(i): 333
22 print(i, end='') 22
1 print() 1
19. Print no. a=int(input("Enter a no:")) Enter a no:7
Names form if a==1: Seven
1 to 9 using print("One")
if-else elif a==2:
print("Two")
elif a==3:
print("Three")
elif a==4:
print("Four")
elif a==5:
print("Five")
elif a==6:
print("Six")
elif a==7:
print("Seven")
elif a==8:
print("Eight")
elif a==9:
print("Nine")
else:
print("Choose between 0 and 9")
20. Print the a=int(input("Enter a no:")) Enter a no:5
decade if a==1: Fifty
name using if print("Ten")
else elif a==2:
print("Twenty")
elif a==3:
print("Thirty")
elif a==4:
print("Fourty")
elif a==5:
print("Fifty")
elif a==6:
print("Sixty")
elif a==7:
print("Seventy")
elif a==8:
print("Eighty")
elif a==9:
print("Ninety")
else:
print("Choose a decade no.")
21. Print no. a=int(input("Enter a no:")) Enter a no:17
Names from if a==11: Seventeen
11 to 19 print("Eleven")
elif a==12:
print("Twelve")
elif a==13:
print("Thirteen")
elif a==14:
print("Fourteen")
elif a==15:
print("Fifteen")
elif a==16:
print("Sixteen")
elif a==17:
print("Seventeen")
elif a==18:
print("Eighteen")
elif a==19:
print("Nineteen")
else:
print("Choose a no. between 11 and 19")
22. No. Names ones=["Zero", "One", "Two", "Three", "Four", Enter a no.96
from 0-99 "Five", "Six", "Seven", "Eight", "Nine"] Ninety Six
teen=["Ten", "Eleven", "Twelve", "Thirteen",
"Fourteen", "Fifteen", "Sixteen", "Seventeen",
"Eighteen", "Nineteen"]
tens=["", “”, "Twenty", "Thirty", "Forty", "Fifty",
"Sixty", "Seventy", "Eighty", "Ninety"]
a=int(input("Enter a no."))
r=a%10
q=a//10
if a < 10:
print(ones[r])
elif a < 20:
print(teen[r])
else:
if r==0:
print(tens[q])
else:
print(tens[q], ones[r])
23. No. Names ones=["Zero", "One", "Two", "Three", "Four", Enter a no.357
from 0-999 "Five", "Six", "Seven", "Eight", "Nine"] Three Hundred Sixty Seven
teen=["Ten", "Eleven", "Twelve", "Thirteen",
"Fourteen", "Fifteen", "Sixteen", "Seventeen",
"Eighteen", "Nineteen"]
tens=["", "Twenty", "Thirty", "Forty", "Fifty",
"Sixty", "Seventy", "Eighty", "Ninety"]
a=int(input("Enter a no."))
h=a//100 # hundreds place
t=(a%100)//10 # tens place
r=a%10 # ones place

# Case 1: Single digit (0–9)


if a < 10:
print(ones[r])
# Case 2: Numbers between 10–19
elif a < 20:
print(teen[r])
# Case 3: Two-digit numbers (20–99)
elif a < 100:
if r == 0: # exact multiple of 10
print(tens[t])
else: # tens + ones
print(tens[t], ones[r])
# Case 4: Three-digit numbers (100–999)
else:
# Print the hundreds part
print(ones[h], "Hundred", end=" ")
# If the last two digits are zero (e.g., 100, 200,
900)
if a % 100 == 0:
print()
# If last two digits are from 1–9
elif a % 100 < 10:
print(ones[r])
# If last two digits are from 10–19
elif a % 100 < 20:
print(teen[a % 100 - 10])
# If last two digits are 20–99
else:
if r == 0: # e.g., 120, 350
print(tens[t])
else: # e.g., 234 = Two Hundred Thirty Four
print(tens[t], ones[r])
24. Write the a=int(input("Enter a 3 digit no. :")) Enter a 3 digit no. :294
ones, tens, h=a//100 Ones : 4
hundred t=(a%100)//10 Tens : 9
digit from a 3 o=a%10 Hundred : 2
digit no. print("Ones :", o)
print("Tens :", t)
print("Hundred :", h)
25. Take 3 no. a=int(input("Enter a single digit no. :")) Enter a single digit no. :2
From user, a, b=int(input("Enter a single digit no. :")) Enter a single digit no. :6
b, c and c=int(input("Enter a single digit no. :")) Enter a single digit no. :8
write it as abc=int(str(a)+str(b)+str(c)) 268
abc. print(abc)

Extra
No Satement Program Ouptput
1. Check a=int(input("Enter the no. of elements in a list:")) Enter the no. of elements in a
whether a list_1=[] list:3
list is for i in range(a): Enter element:12
palindrome. b=input("Enter element:") Enter element:33
list_1.append(b) Enter element:12
print(list_1) ['12', '33', '12']
Palindrome
list_2=list_1[::-1]

if list_1==list_2:
print("Palindrome")
else:
print("Not a palindrome")
2. Check how a=int(input("Enter the no. of studnets:")) Enter the no. of studnets:4
many list_1=[] Enter the grade:A
students got for i in range(a): Enter the grade:B
A grade. b=input("Enter the grade:") Enter the grade:A
list_1.append(b) Enter the grade:C
2
print(list_1.count("A"))
3. Calculate def square(): Enter a no :2
square using a=int(input("Enter a no :")) 4
def s=a*a
return s

print(square())
4. Calculate CI def interest(): Enter the principal:1000
and SI using p=int(input("Enter the principal:")) Enter the rate:10
def r=int(input("Enter the rate:")) Enter the time period:2
t=int(input("Enter the time period:")) SI = 200.0
si=(p*t*r)/100 CI = 210.00000000000023
ci=(p*((1+r/100)**t))-p
print("SI =", si)
print("CI =", ci)

interest()
5. Follow these # Step 1: Input elements in a list Enter the first element
steps in lst=[] (integer): 32
coments first=int(input("Enter the first element: ")) The final tuple is: (32, 64)
[Link](first)

# Step 2: Enter 64 at second place


[Link](1, 64)

# Step 3: Convert list into tuple


t=tuple(lst)

# Step 4: Print tuple


print("The final tuple is:", t)
6. Foloow the # Step 1: Take a sentence and print it Enter a sentence: Navya Phogat
steps in sen=input("Enter a sentence: ") is my name
comments print("Original sentence:", sen) Original sentence: Navya
Phogat is my name
# Step 2: Convert the sentence into uppercase Uppercase: NAVYA PHOGAT IS
us= [Link]() MY NAME
print("Uppercase:", us) Words arranged by length: ['is',
'my', 'name', 'Navya', 'Phogat']
# Step 3: Arrange words in ascending order by
number of letters
words = [Link]()
sorted_words = sorted(words, key=len)

print("Words arranged by length:", sorted_words)


7. Question In import math Enter the value of x:3
notes copy x=int(input("Enter the value of x:")) Enter the value of n:4
last part n=int(input("Enter the value of n:")) 0.23868312757201646
s=0
for i in range(1,n+1):
a=i+1
s=s+i/[Link](x,a)
print(s)
8. Question In import math Enter the value of x:4
notes copy x=int(input("Enter the value of x:")) Enter the value of n:7
last part n=int(input("Enter the value of n:")) 0.16009521484375
sum=0
for i in range(1,n+1):
if i%2==0:
sum=sum-i/[Link](x,i)
else:
sum=sum+i/[Link](x,i)
print(sum)
9. Question In import math Enter the value of y: 3
notes copy y = float(input("Enter the value of y: ")) Enter the starting value a: 5
last part a = int(input("Enter the starting value a: ")) Enter the number of terms n: 2
n = int(input("Enter the number of terms n: ")) 0.03200731595793324
total = 0
for i in range(n + 1):
total=total+(a+i)/[Link](y, a + i)
print(total)

You might also like