KEMBAR78
Program CSC 1-20 | PDF | String (Computer Science) | Letter Case
0% found this document useful (0 votes)
25 views23 pages

Program CSC 1-20

The document contains a series of Python programs that demonstrate various programming concepts such as calculating interest, determining the day of the year, reversing numbers, finding the largest of three numbers, checking leap years, and more. Each program includes input prompts, logic for processing the input, and output statements to display results. The programs cover a wide range of topics including loops, conditionals, string manipulation, and data structures.
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)
25 views23 pages

Program CSC 1-20

The document contains a series of Python programs that demonstrate various programming concepts such as calculating interest, determining the day of the year, reversing numbers, finding the largest of three numbers, checking leap years, and more. Each program includes input prompts, logic for processing the input, and output statements to display results. The programs cover a wide range of topics including loops, conditionals, string manipulation, and data structures.
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
You are on page 1/ 23

1 Program to compute the simple interest and

compound interest.

INPUT
p = float(input("Enter principal ")
r = float(input("Enter rate ")
t = float(input("Enter time ")
SI = (p*r*t) / 100
print("Simple interest = ", SI)
CI = p*((1+(r/100))**t)
print("Compound interest =",CI)

OUTPUT
Enter principal 78
Enter rate 35
Enter time 22
Simple interest = 600.6
Compound interest = 57469.51202977532
2. Program to take two inputs for day, month and then
calculate which day of the year, the given date is. ( For
simplicity, take 30 days for all months. If you give input
as Day 8 , month 3 then it should print “Day of the
year : 68)

INPUT
m = int(input("Enter Month"))
d = int(input("Enter Day"))
n = (m-1)*30+d
print("The day of the year is", n)

OUTPUT
Enter Month: 12
Enter Day: 12
The day of the year is 342
3. Program to read the time in seconds and prints it in
form: minutes and seconds.(Use floor
division and modulus operator).

INPUT
TS = int(input("Enter seconds"))
m = TS//60
s = TS%60
print(m ,"minutes and ",s ,"seconds")

OUTPUT
Enter seconds1298
21 minutes and 38 seconds
4.Program to take a three digit number and print the
reversed number(Use floor division and modulus
operator). If you input 456 then the program should
print 654

INPUT
x = int(input("Enter a three digit number"))
d1 = x%10
x//=10
d2 = x%10
x//=10
d3 = x%10
y = (d1*100 + d2*10 + d3)
print ("the reverse of the number ",y)

OUTPUT
Enter a three digit number123
the reverse of the number 321
5. Program to read three numbers and print the biggest
number(use simple if statement)

INPUT
a = int(input("a = "))
b = int(input("b = "))
c = int(input("c = "))
if a>b and a>c:
print("a is greater")
elif b>a and b>c:
print("b is greater")
else:
print(" c is greater")

OUTPUT
a = 12
b = 342
c=2
b is greater
6. Program to check whether the given year is a leap
year or not(use if-else statement)

INPUT
y = int(INPUT("Enter a year"))
if y%4==0:
print("It is a leap year")
else:
print("It is not a leap year")

OUTPUT
Enter a year: 2012
It is a leap year
Enter a year: 2010
It is not leap year
7. Program to input length of three sides of a triangle.
Then check if these sides will form a triangle or not.

INPUT
a = int(input("Enter first side: "))
b = int(input("Enter second side: "))
c = int(input("Enter third side: "))
if a+b>c and a+c>b and b+c>a:
print("Triangle is possible")
else:
print("Triangle is not possible")

OUTPUT
Enter first side: 4
Enter second side: 3
Enter third side: 5
Triangle is possible
8. Program to read a character and check whether it is
an upper case alphabet, lower case
alphabet, digit or a special character(use if-elif-else
statement)

INPUT
ch = input("Enter a letter or number or special character")
if (ch >= 'A' and ch <= 'Z'):
print(ch,"is an UpperCase character")
elif (ch >= 'a' and ch <= 'z'):
print(ch,"is an LowerCase character")
elif (ch >= "1" and ch <= "9"):
print(ch," is a number")
else:
print(ch,"is a special character")

OUTPUT
Enter a letter or number or special character: A
A is an UpperCase character
9. Menu driven program that displays the result of the
following evaluations based on the user’s
choice.
A. Absolute value of a number
B. Natural logarithm of a number
C. Square root of a number
D. A random number between 0 and 100

INPUT
import math
print("Enter one of the options ")
print("A. Absolute value of a number B. Natural logarithm of a
number C. Square root of a number D. A random number
between 0 and 100")
ch = int(input("Enter choice: "))
n1 = int(input("Enter number: "))
if ch == A:
a = math.fabs(n1)
print(a)
elif ch == B:
b = math.log(n1)
print(b)
elif ch == C:
c = math.sqrt(n1)
print(c)
elif ch == D:
import random
print(random.randrange(0,101))
else:
print("Enter a valid option")
OUTPUT
Enter one of the options
1. Absolute value of a number 2. Natural logarithm of a number
3. Square root of a number 4. A random number between 0 and
100
Enter choice: 3
Enter number: 400
20.0
10. Program to print Fibonacci series (use for
loop)

INPUT
n = int(input("Enter a number: "))
a=1
b=1
print(a)
print(b)
for c in range(1,n+1):
c = a+b
print(c)
a,b = b,cz

OUTPUT
Enter a number: 6
1
1
2
3
5
8
13
21
11. Program to input the value of x and n and
print the sum of the following series:
1+x+x 2 + x 3 +…..x n

INPUT
n = int(input("Enter the value of n"))
x = int(input("Enter the value of x"))
s=0
for s in range(n+1):
s+=x**s
print("sum of first",n,"terms is ",s)

OUTPUT
Enter the value of n 4
Enter the value of x 3
sum of first 4 terms is 85
12. Program to print the sum of the following
series: (use for loop) 1+ 1/1! +1/2! + 1/3!+…..+1/n!

INPUT
n=int(input("Enter a number "))
x=1
s=1
for i in range(1,n+1):
for j in range(1,i+1):
x*=i
s+=1/x
print(s)

OUTPUT
Enter a number 3
2.0
2.75
2.8703703703703702
13. Program to print the following pattern ( use
nested for loop)
12345
1234
123
12
1

INPUT
n = int(input("Enter a number: "))
for i in range(n, 0, -1):
for j in range(1, i + 1):
print(j, end=" ")
print()

OUTPUT
Enter a number: 5
12345
1234
123
12
1
14. Program to print all the Armstrong numbers
between 100 to 2000(use nested loop)
The output should be 153, 370,371,407

INPUT
lower = 100
upper = 2000

for num in range(lower, upper + 1):


order = len(str(num))
sum = 0
temp = num
while temp > 0:
digit = temp % 10
sum += digit ** order
temp //= 10
if num == sum:
print(num)

OUTPUT
153
370
371
407
1634
15. Program to read a string and check whether
it is a palindrome string or not. (use string)

INPUT
n=str(input("Enter a string: "))
if n==n[::-1]:
print("it is a palindrome string ")
else:
print("it is not a palindrome string")

OUTPUT
Enter a string: malayalam
it is a palindrome string
16. Program to read a sentence and print the
original sentence along with the following
statistics
relating to the sentence( use String functions)
a. Number of words
b. Number of characters (including white space
and punctuations)
c. Percentage of characters that are alpha
numeric.

INPUT
x=input("Enter a sentence: ")
l=len(x)
w=s=d=0
for i in x:
if i.isalpha():
w+=1
elif i.isspace():
s+=1
p=w/l*100
print("The sentence " ,x," has the following")
print("total number of characters: ",l)
print("total number of words: ",w-d)
print("Percentage of characters that are alpha numeric:
",p)
OUTPUT
Enter a sentence: hello world 234 46
The sentence hello world 234 46 has the following
total number of characters: 18
total number of words: 10
Percentage of characters that are alpha numeric:
55.55555555555556
17. Program to count frequency of a given
element in a list of numbers(use list)

INPUT
L=eval(input("Enter the list: "))
c = int(input("Enter the element whose frequency is to be
checked: "))
f = L.count(c)
print(f)

OUTPUT
Enter the list: [1,2,1,4,2,4,1,1]
Enter the element whose frequency is to be checked: 1
4
18. Program that prints the sum of the even
indexed elements of L,minus the sum of the odd-
indexed
elements of L. (use list)

INPUT
L=eval(input("Enter your list"))
s1=L[::2]
print(s1)
s2=L[1::2]
print(s2)
sum=0
for i in s1:
sum+=i
a=sum
print(a)
sum=0
for i in s2:
sum+=i
b=sum
print(b)
c=b-a
print(c)
OUTPUT
Enter your list[1,2,3,4,5,6,7,8,9,10]
[1, 3, 5, 7, 9]
[2, 4, 6, 8, 10]
25
30
5
19. Program to create a nested tuple to store roll
number, name,and marks of students.

INPUT
r= int(input("Enter your roll no: "))
n= input("Enter your name: ")
m= int(input("Enter your marks: "))
t=(r,n,m)
print(t)

OUTPUT
Enter your roll no: 12
Enter your name: Roy
Enter your marks: 34
(12, 'Roy', 34)
20. Program to convert a number entered by user
into its corresponding number in words.. (use
dictionary for keys 0-9 and their values as
equivalent words)

INPUT
n=int(input("Enter a number: "))
d={1:"ONE",2:"TWO",3:"THREE",4:"FOUR",5:"FIVE",6:"SI
X",7:"SEVEN",8:"EIGHT",9:"NINE",0:"ZERO"}
s=d[n]
print(s)

OUTPUT
Enter a number: 7
SEVEN

You might also like