0% found this document useful (0 votes)
62 views21 pages

To Print Fibonacci-Series:: Page No. Date

The document contains Python code snippets and outputs for various programs like printing Fibonacci series, taking bio-data input, calculating average marks, printing tables, finding even numbers from 1 to 100, printing patterns, solving quadratic equations, finding mean of lists, making a basic calculator, calculating time taken to cover a distance, calculating simple interest, converting between minutes and hours, swapping variable values, and implementing a number guessing game.

Uploaded by

Carlos
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)
62 views21 pages

To Print Fibonacci-Series:: Page No. Date

The document contains Python code snippets and outputs for various programs like printing Fibonacci series, taking bio-data input, calculating average marks, printing tables, finding even numbers from 1 to 100, printing patterns, solving quadratic equations, finding mean of lists, making a basic calculator, calculating time taken to cover a distance, calculating simple interest, converting between minutes and hours, swapping variable values, and implementing a number guessing game.

Uploaded by

Carlos
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/ 21

Page no.

Date:

20. To print Fibonacci-Series :


n = int(input("Enter the no. of elements to be printed in series = "))
f=0
s=1
print(f, end = ' ' )
print(s,end = ' ' )
for a in range(1,n-1):
t = f+s
print(t,end = ' ' )
f,s = s,t

OUTPUT

Enter the no. of elements to be printed in series = 20


0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181


Page no. Date:

1. Write a program to print Bio-Data taking input from the user.


#Program to take input from user for Bio-Data
nam = input("Enter your name : ")
cls = int(input("Enter your class : "))
m_name = input("Enter your Mother's name : ")
f_nam = input("Enter your Father's name : ")
b_nam = input("Enter your Brother's name : ")
dob= (input("Enter your Date-of-Birth : "))
hobb = input("Enter your hobbies : ")
caste = input("Enter your caste : ")
mar_stat = input("Enter your marital-status: ")
phn_no = input("Enter your phone number: ")
add = input("Enter your address: ")

OUTPUT

Enter your name : Sumit Pandey


Enter your class : 11
Enter your Mother's name : Mrs. Kamla Pandey
Enter your Father's name : Mr. D. B. Pandey
Enter your Brother's name : Amit Pandey
Enter your Date-of-Birth : 5 Jan 2003
Enter your hobbies : Reading novels, Playing Football, Listening music,Writing
Poems etc.
Enter your caste : General
Enter your marital-status: Unmarried
Enter your phone number: 9911783554
Enter your address: 51/171, Street No. 15, Shivaji Park, Gurugram(HR)

Page no. Date:

2. To Calculate average marks in five subjects.


#To calculate avg marks
st_name = input("Enter student's name:")
clas = input("Enter your class:")
age = input("Enter your age:")
print("Enter your number in five subjects: ")
eng = float(input("Enter your marks in English:"))
physics = float(input("Enter your marks in Physics:"))
chem = float(input("Enter your marks in Chemistry:"))
cs = float(input("Enter your marks in Computer-Science:"))
maths = float(input("Enter your marks in Maths:"))
avg = ((eng+physics+chem+cs+maths)/370)*100
print("Average marks in five subjects: ", avg)

OUTPUT
Enter student's name: Sumit Pandey
Enter your class: 11
Enter your age: 16
Enter your number in five subjects:
Enter your marks in English: 58.5
Enter your marks in Physics: 38.5
Enter your marks in Chemistry: 56
Enter your marks in Computer-Science: 64
Enter your marks in Maths: 74
Average marks in five subjects: 78.64864864864865


Page no. Date:

7. Write a program to print a table


#To print a table of user's choice
no_ = int(input("Enter a number to get it's table = "))
for a in range(1,11):
print(no_ ,"X", a, "=",no_*a)

OUTPUT

Enter a number to get it's table = 11127


11127 X 1 = 11127
11127 X 2 = 22254
11127 X 3 = 33381
11127 X 4 = 44508
11127 X 5 = 55635
11127 X 6 = 66762
11127 X 7 = 77889
11127 X 8 = 89016
11127 X 9 = 100143
11127 X 10 = 111270


Page no. Date:

8. Write a program to print even numbers from 1 to 100.


#To print even number from 1 to 100
for a in range(1,101):
if a%2 == 0:
print(a, end = " ")

OUTPUT

2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34
36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66
68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98
100


Page no. Date:

19. To print a pattern


for i in range(5):
for j in range(5):
if i < 3 :
if j == 2 - i or j == 2 + i :
print("*" , end="")
else :
print(" " , end = "")
else :
if j == i-2 or j == 6 - i :
print("*" , end="")
else :
print(" " , end = "")
print()

OUTPUT

*
**
* *
**
*


Page no. Date:

21. Write a program to solve a quadratic equation


#To solve a Quadratic equation
print("Equation = 4x^2 + 6x +2")
x = int(input("Enter the value of x: "))
ans = 4*(x**2) + (6*x) + 2
print("Solution of the equation = ",ans)

OUTPUT
Equation = 4x^2 + 6x +2
Enter the value of x: 5
Solution of the equation = 132


Page no. Date:

12. Write a program to find the mean of a given list


print("Program for mean of a given list")
l1 = list(eval(input("Enter the numbers for list = ")))
print(l1)
total = sum(l1)
a = len(l1)
print("Mean of the given list = ",total/a)

OUTPUT
Program for mean of a given list
Enter the numbers for list = 5,39,12,27
[5, 39, 12, 27]
Mean of the given list = 20.75


Page no. Date:

11. Write a program to make a mathematical Calculator.


# To make a calculator using python
print("1. Addition")
print("2. Subtraction")
print("3. Multiplication")
print("4. Division")
print("5. Exponent")
choice = int(input("Enter your choice = "))
if (choice>=6):
print("Wrong value entered by the user")
if choice == 5:
no1 = int(input("Enter the no. = "))
no2 = int(input("Enter the power = "))
a = no1**no2
print("Result = ", a)
if (choice>=1 and choice<=4):
print("Enter the values")
num1 = int(input("Enter the no. 1 = "))
num2 = int(input("Enter the no. 2 = "))
if choice == 1:
sumit = num1 + num2
print("Result = ", sumit)
elif choice == 2:
a = num1 - num2
print("Result = ", a)
elif choice == 3:
a = num1*num2


Page no. Date:

print("Result = ", a)
elif choice == 4:
a = num1/num2
print("Result = ", a)

OUTPUT
1. Addition
2. Subtraction
3. Multiplication
4. Division
5. Exponent
Enter your choice = 1
Enter the values
Enter the no. 1 = 286
Enter the no. 2 = 171
Result = 457


Page no. Date:

3. A student has to travel a distance of 450 km by car at a certain


average speed. Write python script to find the total time taken
to cover the distance.

#To find the total time taken to cover the distance


print("Total distance = 450km")
spd = int(input("Enter the average speed in km/hr = "))
t = 450/spd
print("Total time taken = ",t,"hr")

OUTPUT
Total distance = 450km
Enter the average speed in km/hr = 45
Total time taken = 10.0 hr


Page no. Date:

4. Write a python code to calculate simple interest by inputting


the value of principle amount and rate from the user for a
time-period of 5 years.

pri_pl = int(input("Enter principle amount = "))


rate = int(input("Enter Rate = "))
print("Time period = 5 years")
si = (pri_pl*rate*5)/100
print("Simple Interest = ",si)

OUTPUT
Enter principle amount = 1000
Enter Rate = 5
Time period = 5 years
Simple Interest = 250.0


Page no. Date:

5. Write a python code to convert the time inputted in minutes into hours
and vice-versa.

print("1. Convert minutes in hours")


print("2, Convert hours in minutes")
choice = int(input("Enter your choice in number(1 or 2) = "))
if (choice>=3 or choice == 0):
print("Invalid value")
elif choice == 1:
min = float(input("Enter time in minutes = "))
hour = min/60
print("Time in hours = ",hour,"hr")
elif choice == 2:
hour = float(input("Enter time in hours = "))
min = hour*60
print("Time in minutes = ",min,"min")

OUTPUT
1. Convert minutes in hours
2, Convert hours in minutes
Enter your choice in number(1 or 2) = 1
Enter time in minutes = 180
Time in hours = 3.0 hr


Page no. Date:

6. Write a python code to swap the values of two variables a and b, using
multiple assignment statements.

a,b = 10,15
a,b = b,a
print(a)
print(b)

OUTPUT
15
10


Page no. Date:

22. Program to implement ‘guess the number’ game .


import random
number = random.randint(10,50)
ctr = 0
while ctr<5:
guess = int(input("Guess a number in range 10..50:"))
if guess == number:
print("You win!! :")

break
else:
ctr+=1
if not ctr<5:
print("You losse :(\n The number was",number)

OUTPUT
Guess a number in range 10..50:5
Guess a number in range 10..50:27
Guess a number in range 10..50:12
Guess a number in range 10..50:39
Guess a number in range 10..50:50
You losse :(
The number was 47


Page no. Date:


Page no. Date:


Page no. Date:


Page no. Date:


Page no. Date:


Page no. Date:

You might also like