Basic Codes of CS
-By Daksh Sachdev XI-A
1.A student has to travel a distance of 450 km by car at a ceratin average speed. Write
a python script and find the total time taken to cover the distance.
In [ ]: speed = eval(input("Enter the average speed in km/h:"))
T = 450/speed
print("The time taken to cover the distance is",T,"hours")
Enter the average speed in km/h:40
The time taken to cover the distance is 11.25 hours
2. Write a python code to calculate simple interest by inputting the values of principal
amount and rate from user for a time period of 5 years.
In [ ]: P = eval(input("Enter principal amount in rupees:"))
R = eval(input("Enter the rate of interest in %:"))
SI = (P*R*5)/100
print("The Simple Interest accumulated over a period of 5 years is:", SI)
Enter principal amount in rupees:5000
Enter the rate of interest in %:10
The Simple Interest accumulated over a period of 5 years is: 2500.0
[Link] a program to convert the time inputted in minutes into hours and remaining
minutes.
In [ ]: time = eval(input('Enter the time in minutes to be converted:'))
hours = time//60
minutes = time%60
print(hours,'hours',minutes,'minutes')
Enter the time in minutes to be converted:579
9 hours 39 minutes
[Link] a python program that accepts radius of a circle and prints its area.
In [ ]: radius = eval(input('Enter the radius of the circle:'))
area = 3.14*radius*radius
print('The area of the circle is',area)
Enter the radius of the circle:12
The area of the circle is 452.15999999999997
[Link] a python program that accepts marks in 5 subjects and outputs average
marks.
In [ ]: a=eval(input('enter the marks of the first subject:'))
b=eval(input('enter the marks of the second subject:'))
c=eval(input('enter the marks of the third subject:'))
d=eval(input('enter the marks of the fourth subject:'))
e=eval(input('enter the marks of the fifth subject:'))
avg=(a+b+c+d+e)/5
enter the marks of the first subject:98
enter the marks of the second subject:97
enter the marks of the third subject:98
enter the marks of the fourth subject:95
enter the marks of the fifth subject:94
The average marks are: 96.4
[Link] a program to read three numbers in three variables and swap first two
variables with the sums of first and second, and third numbers respectively.
In [ ]: a=eval(input('enter the first number:'))
b=eval(input('enter the second number:'))
c=eval(input('enter the third number:'))
a,b=a+b,b+c
print('The swapped numbers are',a,b)
enter the first number:5
enter the second number:25
enter the third number:35
The swapped numbers are 30 60
[Link] a program to print a fibonacci series.
In [ ]: a,b = 0,1
c=int(input("Enter number of terms:"))
print("The fibonacci series is:")
for i in range(c):
print(a, end = " ")
a,b = b, a+b
Enter number of terms:25
The fibonacci series is:
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 6765 10946 17711 2
8657 46368
In [ ]: !jupyter nbconvert --to html /content/[Link]
[NbConvertApp] Converting notebook /content/[Link] to html
[NbConvertApp] Writing 592795 bytes to /content/[Link]